【发布时间】:2020-04-10 21:51:19
【问题描述】:
我的桌子如下所示:
ID Date IsFull
1 2020-01-05 0
1 2020-02-05 0
1 2020-02-25 1
1 2020-03-01 1
1 2020-03-20 1
我想显示 ID = 1 的月份数
在给定月份中 sum(isfull)/count(*) > .6(该月超过 60% 的时间 isfull = 1)
所以最终的输出应该是
ID HowManyMonths
1 1 --------(Only month 3----2 out 2 cases)
如果问题变为 sum(isfull)/count(*) > .4
那么最终的输出应该是
ID HowManyMonths
1 2 --------(Month 2 and Month 3)
谢谢!!
【问题讨论】:
标签: sql sql-server tsql date group-by