select 起始时间,终止时间,(select sum(数量) as 数量,sum(价格) as 价格 from (SELECT sh_saletime,sum(sh_totqty) as 数量,sum(sh_totamount) as 价格 from sh_salehistory group by sh_saletime) b where sh_saletime between convert(varchar(8),a.起始时间,108) and convert(varchar(8),a.终止时间,108)) from saletime a
SELECT left(convert(varchar(20),sh_saletime,120),13),sum(sh_totqty),sum(sh_totamount) from sh_salehistory group by left(convert(varchar(20),sh_saletime,120),13)没有调试,应该是类似的语句...
select da = case datepart(hour, sh_saletime) when 9 then '9:00 - 10:00' ... when 16 then '16:00 - 17:00' END, SUM(1),sum(sh_totamount)
from sh_salehistory group by datepart(hour, sh_saletime)
起始时间 终止时间
09:00 10:00
10;00 11:00
11:00 12:00
12:00 13:00
13:00 14:00
14;00 15:00
15:00 16:00
16:00 17:00
我现在试试风云大哥给我的语句谢谢了
from saletime a
from sh_salehistory
group by left(convert(varchar(20),sh_saletime,120),13)没有调试,应该是类似的语句...
...
when 16 then '16:00 - 17:00' END, SUM(1),sum(sh_totamount)
from sh_salehistory group by datepart(hour, sh_saletime)