SQL语句:统计指定字段,等于不同值的条数

方法一:通过group by ,之后count条数实现。
sql:select count(1) from tablename group by columes;
方法二:通过district函数来直接取出唯一字段,之后统计数量:
sql:select count(ditrict(columes)) from tablename;
解释:columes表示的是特殊字段

 

例如:

select DISTINCT count(1) FROM [dbo].[BusinessDZ] where [Time] > ‘2021-03-06 00:00:00’ and [Time] < ‘2021-03-07 00:00:00’ group by [UID];

select DISTINCT count(1) FROM [dbo].[BusinessDZ] where [Time] > ‘2021-03-07 00:00:00’ and [Time] < ‘2021-03-08 00:00:00’ group by [UID];

select DISTINCT count(1) FROM [dbo].[BusinessDZ] where [Time] > ‘2021-03-08 00:00:00’ and [Time] < ‘2021-03-09 00:00:00’ group by [UID];

作用:

统计当天是否有人刷票

 

 

点赞

发表评论

邮箱地址不会被公开。 必填项已用*标注