订单列表根据时间段

时间:2015-11-21 07:47:33

标签: sql-server datetime group-by orders

我有一张桌子" orderdetails"表,我希望订单列表从2015年6月6日到06-30-15每天低于60个订单,基于时间段,如00-01和01-02之类的那样

$http.get('url').success(function(data, status, headers, config) {
                  data.response = data;
                  $('.serverStatus').text(data.response.message);
                  data.calls++;
                  $timeout(poller, 1000);
                });
              };

但是这个查询显示错误的列表...它没有显示在count(orderid)< 60订单显示整体订单,而不是低于每天订单60 ...

1 个答案:

答案 0 :(得分:0)

select * from (
select
 convert(datetime, Convert(varchar(50), OrderDate, 101)) as dateorder,
 count(orderid) as ordercount   
 from
 orderdetails 
 where
 OrderDate between convert(datetime,Convert(varchar(50),'6/01/2015',101)) and convert(datetime,Convert(varchar(50),'06/30/2015',101))   
and transactionid is not null 
and DATEPART(HOUR,OrderDate) between '1' and '2'   
group by
 convert(datetime, Convert(varchar(50), OrderDate, 101)) ) t

where ordercount   < 60