He has done wrong is First Quiry, Why he mentioned Sum? Q. Just filter the category other then tobacoo exceeded 50L Select category, Sales_amout from Sales WHERE category != 'tobacco' AND sales_amount > 5000000 ORDER BY sales_amount DESC LIMIT 3; Correct me if I am wrong!
First, you need to mention "sum" because there is no total sales amount in the given table. Second, you are taking "category" with an aggregate function "sum", so you should use group by. Third, you cannot use aggregate functions such as sum with where clause so sum(total_price) > 5000000 has to be used in having. so, the query will look like this- SELECT category, SUM(price) AS total_sales FROM sales WHERE category != 'Tobacco' GROUP BY category HAVING SUM(price) > 500000 ORDER BY SUM(price) DESC LIMIT 3
@@WhatshappeningUf You said "correct me if I am wrong." So I did. It is not about perspective. It is the answer to the question. Look at the table, the columns, and the question, you will get it. Also, to confirm, I ran the query and got the answer. You answer is correct if there is a table with sales amount for each category. This is different.