不完全正是你想要的,但我認爲你會發現將最左邊的列填充爲值使用ANSI-SQL想...
透視表:
CREATE TABLE DataSet (Col1 varchar(20), Col2 varchar(20))
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.01.04','A0103')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.01.04','A0306')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.01.04','A0309')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.01.04','A0403')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.01','A1403')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.02','A1403')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.03','A0403')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.03','A0703')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.04','A0103')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.04','A0306')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.04','A0309')
INSERT INTO DataSet (Col1, Col2) VALUES ('BK.02.04','A0403')
SELECT Col1,
MAX(CASE Col2 WHEN 'A0103' THEN 'A0103' ELSE '' END) Col2,
MAX(CASE Col2 WHEN 'A0306' THEN 'A0306' ELSE '' END) Col3,
MAX(CASE Col2 WHEN 'A0309' THEN 'A0309' ELSE '' END) Col4,
MAX(CASE Col2 WHEN 'A0403' THEN 'A0403' ELSE '' END) Col5,
MAX(CASE Col2 WHEN 'A1403' THEN 'A1403' ELSE '' END) Col6
FROM DataSet
GROUP BY DataSet.Col1
結果:
Col1 Col2 Col3 Col4 Col5 Col6
-------------------- ----- ----- ----- ----- -----
BK.01.04 A0103 A0306 A0309 A0403
BK.02.01 A1403
BK.02.02 A1403
BK.02.03 A0403
BK.02.04 A0103 A0306 A0309 A0403
(5 row(s) affected)
如果您正在使用MS-Access,可以accompl通過使用樞軸表十歲上下同樣的事情:
http://office.microsoft.com/en-us/access-help/designing-your-first-pivottable-pivotchart-views-in-access-HA001034580.aspx
我想像這必須是一個動態的解決方案,因爲該數據可能會改變,你不能保證每個記錄'Col1'值數可能有? – Yuck