sql 分类 汇总语句

Astpiy 2015-07-15 02:26:17
数据如图


我想要得到

每天 类别 为1,2 的 不重复CustID的数量 和 总数
即结果为:

...全文
97 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Astpiy 2015-07-15
  • 打赏
  • 举报
回复
引用 1 楼 yupeigu 的回复:
试试这个:
select convert(varchar(10),CreateDate,120) 时间,
       count(distinct case when typeid = 1 then custid end) 类别1不重复,
	   count(case when typeid = 1 then custid end) 类别1总数,
       count(distinct case when typeid = 2 then custid end) 类别2不重复,
       count(case when typeid = 2 then custid end) 类别2总数

from tb
group by convert(varchar(10),CreateDate,120)
感谢,是可以的。
  • 打赏
  • 举报
回复
试试这个:
select convert(varchar(10),CreateDate,120) 时间,
       count(distinct case when typeid = 1 then custid end) 类别1不重复,
	   count(case when typeid = 1 then custid end) 类别1总数,
       count(distinct case when typeid = 2 then custid end) 类别2不重复,
       count(case when typeid = 2 then custid end) 类别2总数

from tb
group by convert(varchar(10),CreateDate,120)

34,587

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧