我的ms-sql数据库中有一个汇率表,当我查询最后的日期汇率时:
SELECT TOP 4 * FROM tblKur ORDER BY tarih DESC
我写了一个数据透视查询,但它给了我空值,
SELECT top 4 piv.* FROM tblKur
PIVOT(
MAX(satis)
FOR dovizId IN([1],[2],[3],[4])
)AS Piv
ORDER BY tarih DESC
我需要简化我的透视结果,例如:
我该怎么做这个过程?
答案 0 :(得分:1)
SELECT [1] as 1,[2] as 2,[3] as 3,[4] as 4
FROM
(
SELECT top 4 dovizId ,satis FROM tblKur ORDER BY tarih DESC
)PivoitData
PIVOT
(
SUM(satis) for dovizId in ([1],[2],[3],[4])
) AS Pivoting
答案 1 :(得分:0)
试试这个......
SELECT [1] as 1,[2] as 2,[3] as 3,[4] as 4
FROM
(
SELECT dovizId ,satis FROM tblKur
)PivoitData
PIVOT
(
SUM(satis) for dovizId in ([1],[2],[3],[4])
) AS Pivoting