SELECT convert(varchar(2),sh_saletime,108),sum(sh_totqty),sum(sh_totamount)
from sh_salehistory
group by convert(varchar(2),sh_saletime,108)

解决方案 »

  1.   

    建立一个表 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
      

  2.   

    我要做的上个报表不希望建立一个表啊!只想用select语句来实现
    我现在试试风云大哥给我的语句谢谢了
      

  3.   

    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
      

  4.   

    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)没有调试,应该是类似的语句...
      

  5.   

    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)