I want to Apply condition for GROUP BY
.
When the condition city_id != 0
is true, group the list. Otherwise normal list.
I used this query for that:
(
SELECT city_id, sum(sales) as counts
FROM product_sales
WHERE city_id !=0
GROUP BY city_id
)
UNION
(
SELECT city_id, sales
FROM product_sales
WHERE city_id =0
ORDER BY sales_id
)
Anyone can help me avoid the UNION
and get the list in a single query?