我有下表,
Company_ID part_id Serial NO
------------------ ----------- --------------
1 BAU BAU2512
1 BAU BAU3512
1 BAU BAU4512
2 BAU BAU5512
2 BAU BAU6512
2 BAU BAU7512
我想要一个查询来返回这个
Company_id Item#1 Item#2 Item#3
------------------ --------- ------------- -----------
1 BAU2512 BAU3512 BAU4512
2 BAU5512 BAU6512 BAU7512
使用 SQL Server 2008 对查询的任何帮助表示赞赏
创建示例表。
-- Suppress data loading messages
SET NOCOUNT ON
-- Create Sample Data using a Table Varable
DECLARE @Company TABLE
(Company_ID int,
part_ID varchar(30),
SerialNO varchar(30))
-- Load Sample Data
INSERT INTO @Company VALUES (1, 'BAU', 'BAU2512')
INSERT INTO @Company VALUES (1, 'BAU', 'BAU3512')
INSERT INTO @Company VALUES (1, 'BAU', 'BAU4512')
INSERT INTO @Company VALUES (2, 'BAU', 'BAU5512')
INSERT INTO @Company VALUES (2, 'BAU', 'BAU6512')
INSERT INTO @Company VALUES (2, 'BAU', 'BAU7512')