0

如果我有一个带有主键“ID”的表,然后我在列中有其他数据(例如:姓名、地址、电话号码),我如何进行查询以显示姓名、地址和特定ID的PhoneNum(整行)垂直?

如果需要,我可以发布一张图片来解释我的意思。

谢谢!:)

4

1 回答 1

1

对于名为 [Clients] 的表中的示例数据

ID  LastName    FirstName   Email
--  --------    ---------   -----
1   Thompson    Gord        gord@example.com
2   Loblaw      Bob         bob@example.com
3   Kingsley    Hank        hank@example.com

查询

SELECT "LastName" AS fld, LastName AS val FROM Clients WHERE ID=1
UNION ALL
SELECT "FirstName" AS fld, FirstName AS val FROM Clients WHERE ID=1
UNION ALL
SELECT "Email" AS fld, Email AS val FROM Clients WHERE ID=1;

返回

fld         val
---         ---
LastName    Thompson
FirstName   Gord
Email       gord@example.com
于 2013-04-18T08:31:11.407 回答