我想在sql 2000中将行2行转换为2列 不使用枢轴
例如:
A B C
---- ---- -------
78 68 3
我希望输出为
Projects Count
--------- -------
A 78
B 68
C 3
答案 0 :(得分:1)
SELECT
pivot.field,
CASE pivot.field
WHEN 'A' THEN A
WHEN 'B' THEN B
WHEN 'C' THEN C
END as value
FROM
my_table
CROSS JOIN
(SELECT 'A' AS field UNION ALL SELECT 'B' UNION ALL SELECT 'C') AS pivot
答案 1 :(得分:0)
如果我理解正确,您确实需要透视查询:
select 'A' as Projects, A as my_count from mytab
union all
select 'B' as Projects, B as my_count from mytab
union all
select 'C' as Projects, C as my_count from mytab
(我用my_count替换了count,因为COUNT是SQL中的保留字。)