按月份明智的报告

时间:2014-04-02 15:08:38

标签: c# sql

是否可以在sql中获取此报告格式。我尝试了各种各样的方法,但没有运气..这一点上的任何一点都会对我有所帮助..我可以从表中获取名称,但是如何在sql中提供日期明智的报告。我不想使用任何报告

NAME    1  2   3  4   5   6   7   8   9   10   11   12  13  14  15  16   17   18   19   20   21  22  23 24 (date)  
smrithi 10 20  34 45  55  55  66  77  33   44   55  56  44  66  77  88    55  22   33    11  44  99  77  88 (tickets)
XYZ     10 20  34 45  55  55  66  77  33   44   55  56  44  66  77  88    55  22   33    11  44  99  77  88

这是我试过的......

SELECT *

FROM 
( SELECT CAST(DAY(t_date_time_issued) AS VARCHAR(4)) AS SaleDay,
CAST(MONTH(t_date_time_issued) AS VARCHAR(4)) AS SaleYear

FROM  dbo.tickets) as ts
PIVOT
( 
count(t_reference) 
FOR SaleDay IN ( [1],[2],[3],[4],[5],[6],[7],[8],[9],
[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],
[22],[23],[24] ) ) AS pvt

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

    SELECT Name, [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24] 
    FROM
    ( 
     SELECT Name, 
     CAST(DAY(t_date_time_issued) AS VARCHAR(4)) AS SaleDay,
     t_reference
     FROM  dbo.tickets) AS ts
    PIVOT
    (
    count(t_reference)
    FOR SaleDay IN ( [1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12],[13],[14],[15],[16],[17],[18],[19],[20],[21],[22],[23],[24] )
    ) AS pvt

http://sqlfiddle.com/#!6/052ff/5