0
下面是一個T-SQL查詢:列不按
SELECT
A.DateStamp,
CASE WHEN A.T = 10 THEN A.counts END AS HT,
CASE WHEN A.T = 98 THEN A.counts END AS BP,
CASE WHEN A.T = 94 THEN A.counts END AS MP,
CASE WHEN A.T = 12 THEN A.counts END AS SP
FROM
A
WHERE
(A.date_time BETWEEN GETDATE() - 60 AND GETDATE() - 30) -- say
--GROUP BY A.DateStamp,A.T,A.counts
ORDER BY
CONVERT(DATE, A.DateStamp) ASC
它運作良好。以前我使用表A的多個副本並全部加入。在這裏結果是正確的,但分裂像多行:
date | BP | MP | SP | HT |
-----------+----+----+----+----+
22/10/2017 12 34 56 78
Looks Like -- -- -- --
22/10/2017 12 -- -- --
22/10/2017 -- 34 -- --
22/10/2017 -- -- 56 --
22/10/2017 -- -- -- 78