每小时销售报告

时间:2014-06-05 02:04:24

标签: sql-server visual-studio-2010

早上好。 我需要你的帮助。 我正在做销售报告,但我无法得到我想要的输出。

我的代码是:

Select Cast(TIME As Varchar(100))+ '-' + CAST(DATEADD( MINUTE, 59, TIME)As varchar(100))  As TIME, SUM (TOTAL) as HOURLY_SALES 
From tblSales
Where Mall = 'Mall1' and ORDATE  = '6/2/2014' and VOID = 'N' 
Group By OTIME

它给了我这个输出:

   Time                    HOURLY_SALES 
12:00-Jan  1 1900 12:59PM   295.00
13:00-Jan  1 1900  1:59PM   2122.86
14:00-Jan  1 1900  2:59PM   2230.00
15:00-Jan  1 1900  3:59PM   1800.00
16:00-Jan  1 1900  4:59PM   3090.00
17:00-Jan  1 1900  5:59PM   880.00
18:00-Jan  1 1900  6:59PM   652.86
19:00-Jan  1 1900  7:59PM   1890.00
20:00-Jan  1 1900  8:59PM   2272.86
21:00-Jan  1 1900  9:59PM   520.00

我不知道约会的来源。 请帮我删除日期。

输出应该是这样的:

       Time              HOURLY_SALES

    12:00- 12:59PM  295.00
    13:00-  1:59PM  2122.86
    14:00-  2:59PM  2230.00
    15:00- 3:59PM   1800.00
    16:00-  4:59PM  3090.00
    17:00-  5:59PM  880.00
    18:00-  6:59PM  652.86
    19:00-  7:59PM  1890.00
    20:00- 8:59PM   2272.86
    21:00-  9:59PM  520.00

我正在使用visual studio 2010和ms sql server 2008 希望你能帮助我。 非常感谢你。

1 个答案:

答案 0 :(得分:1)

这样做呢?

select (cast(datepart(hour, [time]) as varchar(255)) + ':00 -' +
        cast(datepart(hour, [time]) as varchar(255)) + ':59'
       ) as [time],
       SUM (TOTAL) as HOURLY_SALES 
From tblSales
Where Mall = 'Mall1' and ORDATE  = '6/2/2014' and VOID = 'N' 
Group By cast(datepart(hour, [time]) AS VARCHAR(255));