我想将 销售日期 列的datetime类型的数据按小时分类,统计4月1号这天每小时的销量和
select hour(销售日期) as 时 ,sum(货物数量) as 数量 from sell where  month(销售日期) like '4' and year(销售日期) like '2010' and day(销售日期) like '1' group by hour(销售日期);
但是提示 'hour' 不是可以识别的 函数名。
该怎么写?

解决方案 »

  1.   

    hour(销售日期)
    改成DATEPART(HH,销售日期)
      

  2.   

    select convert(varchar(2),销售日期,108) as 时 ,sum(货物数量) as 数量 from sell where month(销售日期) like '4' and year(销售日期) like '2010' and day(销售日期) like '1' group by convert(varchar(2),销售日期,108);
      

  3.   

    --or
    select datepart(hh,销售日期) as 时 ,sum(货物数量) as 数量 
    from sell 
    where month(销售日期) like '4'
     and year(销售日期) like '2010'
     and day(销售日期) like '1' 
    group by datepart(hh,销售日期);