我有一组这样的数据
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
现在我想检查特定时期的总价格、最低可用性和 serviceid 是多少
例如
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 分组,则计数无效。不知道如何获取总和、最小可用性和检查连续日期。
编辑 如果我想要一个包含详细规范的结果集。并过滤掉 min(availability) = 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