这是示例表:
Table1
| id | one | two | three | four | five | six |
|--------------------------------------------|
| 1| 11| 7| 4| 9| 4| 1|
| 2| 12| 9| 3| 8| 19| 32|
| 3| 18| 7| 7| 1| 24| 2|
| 4| 9| 1| 15| 6| 6| 4|
目前我在表上使用的查询是这样的:
SELECT id, Max(colx) AS colWithMax
FROM (
SELECT id, one AS Colx From Table1 UNION ALL
SELECT id, two AS Colx From Table1 UNION ALL
SELECT id, three AS Colx From Table1 UNION ALL
SELECT id, four AS Colx From Table1 UNION ALL
SELECT id, five AS Colx From Table1 UNION ALL
SELECT id, six AS Colx From Table1
)
group by id;
我得到的输出是:
ID | colWithMax
-- | ---------
1 | 11
2 | 32
3 | 24
4 | 15
我的问题是如何更改我的查询,以便我的输出将显示列名而不是列中的值?
根据示例表,所需的输出将是:
ID | colWithMax
-- | ---------
1 | one
2 | six
3 | five
4 | three
注意:我对sql有基本的了解,之前从未使用过ms-access。请在您的回答中尽可能描述性。谢谢你。