我在SQL Server表中有数据,结构如下:
QuickFIX/J
我想显示以下查询结果:
Engine_No Date Process Bolt_No1 B1Value1 B1Value2 B1Value3 Bolt_No2 B2Value1 B2Value2 B2Value3 Bolt_No3 B3Value1 B3Value2 B3Value3 Bolt_No4 B4Value1 B4Value2 B4Value3
有人可以建议实现此目的的查询吗?
答案 0 :(得分:1)
你可以选择这样的选择:
SELECT
*
FROM
(
(
SELECT
Engine_No,
Date,
Process,
Bolt_No1,
B1Value1,
B1Value2,
B1Value3
FROM
Engines
) UNION (
SELECT
Engine_No,
Date,
Process,
Bolt_No2,
B2Value1,
B2Value2,
B2Value3
FROM
Engines
) UNION (
SELECT
Engine_No,
Date,
Process,
Bolt_No3,
B3Value1,
B3Value2,
B3Value3
FROM
Engines
) UNION (
SELECT
Engine_No,
Date,
Process,
Bolt_No4,
B4Value1,
B4Value2,
B4Value3
FROM
Engines
)
) AS tmp
ORDER BY Engine_No
唯一的问题是,由于每列只能有一个名称,因此您不知道哪些行包含哪些列。
在这种情况下,您通常会选择所需的内容,然后将其格式化为您希望以您显示的语言显示的方式。