答案 0 :(得分:0)
sql lite中没有任何PIVOT
函数。您提供的链接指向哪个。但你可以这样做:
SELECT
yourtable.Id,
yourtable.Date,
MAX(CASE WHEN [Type]=1 THEN [Value] ELSE NULL END) AS [1],
MAX(CASE WHEN [Type]=2 THEN [Value] ELSE NULL END) AS [2],
MAX(CASE WHEN [Type]=3 THEN [Value] ELSE NULL END) AS [3]
FROM
yourtable
GROUP BY
yourtable.Id,
yourtable.Date
如果您想使用数据透视表并使用MSSQL 2012,那么您可以执行此操作:
SELECT
*
FROM
(
SELECT
yourtable.Id,
yourtable.Date,
yourtable.Type,
yourtable.Value
FROM
yourtable
) AS sourceTable
PIVOT
(
MAX(Value)
FOR Type IN([1],[2],[3],[4])
) AS pvt
这将导致:
1 2014-04-01 00:00:00.000 23 NULL NULL NULL
2 2014-04-01 00:00:00.000 56 NULL NULL NULL
3 2014-04-01 00:00:00.000 12 78 NULL NULL
2 2014-07-01 00:00:00.000 56 NULL NULL NULL
3 2014-07-01 00:00:00.000 12 78 33 NULL