【MySql】 case When...then 和 GROUP BY

Get the sum of timestamp sid

SELECT sum(sid),
case 

-- date_>'20220301' and date_<'20220403' 这个时间范围,作为'20220301-20220403'输出

    when date_>'20220301' and date_<'20220403' then 
    '20220301-20220403'
    when date_>'20220422' and date_<'20220603' then 
    '20220422-20220505' 
end  aa        -- 将时间戳取名为 aa
from  clazz GROUP BY aa        --按时间戳进行分组计算 sum(sid)

result:

 

Guess you like

Origin blog.csdn.net/xudahai513/article/details/126526286