gpt4 book ai didi

mysql - 使用 Group BY 按条件查询列计数

转载 作者:行者123 更新时间:2023-11-29 14:37:22 24 4
gpt4 key购买 nike

表结构

id(int)
dated_on(datetime)
(many_more)

表中包含按 ID 分组的数千条数据。

I want result as id, count of that id, 
also count of id having date difference is week.(i.e. count of data last week)

最佳答案

select
id,
count(id) as cnt,
sum(if(now() - interval 7 day <= dated_on,1,0)) as lastweek
from table
group by id

关于mysql - 使用 Group BY 按条件查询列计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8769142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com