如何查询,高难度
DEPTID RQ JYSJ XSJE XSBS
0101 2007-01-01 09:00:00-10:00:00 100 15
0101 2007-01-01 10:00:00-11:00:00 101 15
0101 2007-01-01 11:00:00-12:00:00 102 15
0101 2007-01-01 12:00:00-13:00:00 103 15
0101 2007-01-01 13:00:00-14:00:00 104 15
0101 2007-01-01 14:00:00-15:00:00 105 15
0101 2007-01-01 15:00:00-16:00:00 106 15
0101 2007-01-01 16:00:00-17:00:00 107 15
0101 2007-01-01 17:00:00-18:00:00 108 15
这个是我的表的结构,和数据,我要实现下面的效果,请教高手如何写查询的语句。
谢谢!
RQ JYSJ JYSJ JYSJ JYSJ
2007-01-01 09:00:00-10:00:00 10:00:00-11:00:00 11:00:00-12:00:00 12:00:00-13:00:00
2007-01-01 100, 15 101,15 102 ,15 103,15
------解决方案--------------------还有销售笔数..
改成这样.
SELECT RQ,
cast(SUM(CASE JYSJ WHEN '09:00:00-10:00:00 ' THEN XSJE ELSE 0 END) as varchar) + ', ' + cast(SUM(CASE JYSJ WHEN '09:00:00-10:00:00 ' THEN XSBS ELSE 0 END) as varchar) as XSJE_1,
...
FROM Table
GROUP BY RQ