我想從所提供的示例表中獲得所需結果中顯示的內容。SQL結果列值作爲結果
我一直在努力與創建SQL來處理這個問題:
CREATE TABLE a (account nvarchar(10), accountname nvarchar(10));
CREATE TABLE b (bid int, bdesc nvarchar(10));
CREATE TABLE C (cid int, bid int, caccount nvarchar(10));
INSERT INTO a VALUES ('a1','a1val');
INSERT INTO a VALUES ('b1','b1val');
INSERT INTO a VALUES ('c1','c1val');
INSERT INTO a VALUES ('d1','d1val');
INSERT INTO b VALUES (1,'val1');
INSERT INTO b VALUES (2,'val2');
INSERT INTO b VALUES (3,'val3');
INSERT INTO c VALUES (1,1,'a1');
INSERT INTO c VALUES (2,1,'b1');
INSERT INTO c VALUES (3,2,'a1');
INSERT INTO c VALUES (4,3,'c1');
--Desired results
--accountname val1 val2 val3
--a1val x x
--b1val x
--c1val x
--d1val
select * from a
select * from b
select * from c
drop table a, b, c
可能重複(http://stackoverflow.com/questions/1768586/sql-convert-rows-to-columns) –