我对交叉表功能有一些问题。
我的表“t”是
date;name;hour;cause;c_p
"2013-06-12";167;14;0;2
"2013-06-12";167;16;0;3
"2013-06-12";167;16;0;4
"2013-06-12";167;19;1;1
"2013-06-12";167;19;0;4
我会有这个“数据透视表” t_pivot
day;name;hour;cause_0;cause_1
"2013-06-12";167;14;2;0 -----sum(c_p)
"2013-06-12";167;16;7;0
"2013-06-12";167;19;4;1
Sql 代码是
SELECT * from crosstab (
'SELECT day,name,hour,cause, SUM(c_p) AS c_p
FROM t
GROUP BY 1,2,3,4
ORDER BY 3 ',
'SELECT DISTINCT cause
FROM i
ORDER BY 1')
AS t_pivot (day date, name integer,hour integer, cause_0 integer,cause_1 integer)
查询结果是一个行表,取决于“ORDER BY”
ORDER BY 3
"2013-06-12";167;14;4;1
ORDER BY 1, ORDER BY 2
"2013-06-12";167;14;7;1
错误在哪里?谢谢f。