SQL Selecting multiple sums?

后端 未结 5 2092
无人及你
无人及你 2021-02-08 17:00

Let\'s say I have a table:

SELECT  SUM(quantity) AS items_sold_since_date,
        product_ID
FROM    Sales
WHERE order_date >= \'01/01/09\'
GROUP BY product_         


        
5条回答
  •  一向
    一向 (楼主)
    2021-02-08 17:45

    SELECT  SUM(CASE WHEN order_date >= '01/01/09' THEN quantity ELSE 0 END) AS items_sold_since_date,
            SUM(quantity) AS items_sold_total,
            product_ID
    FROM    Sales
    GROUP BY product_ID
    

提交回复
热议问题