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

获取时间戳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)

结果:

猜你喜欢

转载自blog.csdn.net/xudahai513/article/details/126526286
今日推荐