我有这样集团按日期和时间并连续日期
date1 Price Availability ServiceID
2012-10-01 50 1 5
2012-10-02 60 1 5
2012-10-03 60 1 5
2012-10-04 60 1 5
2012-10-06 60 1 5
2012-10-07 60 0 5
2012-10-08 60 1 5
一组数据,现在,我要检查什么是总价格,最小的可用性和服务ID为某一特定时期
例如
from 2012-10-01 to 2012-10-03 results would be 170, availability 1 and serviceID 5
from 2012-10-06 to 2012-10-08 results would be 180, availability 0! and serviceID 5
from 2012-10-04 to 2012-10-06 results would be 120, availability 1! and serviceID 5 BUT there is a date missing so availability is 0!
我想是这样
select date1, sum(price), min(availability), service from #t
group by date1, price, availability, service
having count(date1) = datediff(day, @startdate, @enddate)
这不起作用,因为如果我按date1进行分组,则计数无效。不知道如何获得总和,最小可用性和检查连续日期。
编辑 如果我想要一个结果集包含详细的规格。并过滤掉与分钟(可用性)= 0或不连续的日期结果
For example
from 2012-10-01 to 2012-10-03 results would be 170, availability 1 and serviceID 5
date1 Price Availability ServiceID
2012-10-01 50 1 5
2012-10-02 60 1 5
2012-10-03 60 1 5
from 2012-10-06 to 2012-10-08 results would be 180, availability 0! and serviceID 5
date1 Price Availability ServiceID
from 2012-10-04 to 2012-10-06 results would be 120, availability 1! and serviceID 5 BUT
date1 Price Availability ServiceID
从2012-10-04到2012-10-06可能会有180个结果,如果每个有60个值有2个值?缺少日期需要“假”60吗? –
@NenadZivkovic错字 – mko