我有一张像
这样的表格A1 A2 A3 A4 A5 A6
1 1 1 1 1 1
2 2 2 2 2 2
3 3 3 3 3 3
我希望完成以下任务:
SELECT A2 AS B2 WHERE A1 = 1
SELECT A2 AS B3 WHERE A1 = 2
我该怎么做?
答案 0 :(得分:0)
我认为你可以使用这样的查询:
SELECT
CASE WHEN A1 = 1 THEN A2 END As B2,
CASE WHEN A1 = 2 THEN A2 END As B3,
FROM
yourTable;
请注意,B2
与A2
相同,如果A1 = 1
其他为null
,依此类推。
答案 1 :(得分:0)
SELECT
CASE WHEN A1 = 1 THEN A2 END As B2,
CASE WHEN A1 = 2 THEN A2 END As B3
FROM TABLE_NAME
WHERE A1 = 1 OR A1 = 2