I have a sql query for my MYSQL DB and want to limit the results to only 10 sales people instead of 20. I have tried inserting their names inside the query but keep getting error. Also is it possible to rank according to total. The sql query I am using is:
select sales_id, totalbuy, totalsell, totalbuy + totalsell as total from
(select sales_id, SUM(CASE WHEN side= 'buy' THEN 1 ELSE 0 END) AS totalbuy,
SUM(CASE WHEN side= 'sell' THEN 1 ELSE 0 END) AS totalsell
from sales_id where sales_id='sales1', GROUP BY sales_id)q
where it says sales1 I have attempted to add the remaining 9 sales_ids’ using a comma and single quotes but can’t get it to work.
If you want certain sales_id only, use the “IN ” clause.
if you wanna only the top 10 total, remove that line and use LIMIT