SUM() based on a different condition to the SELECT

后端 未结 3 1738
生来不讨喜
生来不讨喜 2021-02-05 20:56

Hi is there a way that I can do the SUM(total_points) based on a different condition to the rest of the SELECT statement, so I want the SUM(total_points) for every row which is

3条回答
  •  忘了有多久
    2021-02-05 21:38

    SELECT ... 
    SUM(CASE
    WHEN track_id <= [your_value] THEN total_points
    ELSE 0
    END
    ) AS total_points, .... 
    

提交回复
热议问题