升了两个星星 散分!!
有时候回答有时候蹭分,不对之处,大家多多包涵!!
顺一个问题吧:
A表:
id name
1 aspx
2 psp
3 jsp
B表:
guid cid gid
1111 1 2
2222 2 3
要求用一个SQL语句得到如下
guid cname gname
1111 aspx psp
2222 psp jsp
答对者另开帖,重重有赏-_-!!!
------解决方案--------------------哦,恭喜:)
------解决方案--------------------抢不到SF
BD也好
恭喜
------解决方案--------------------CREATE TABLE #TMPA
(ID int,
[NAME] varchar(20))
INSERT INTO #TMPA VALUES (1, 'ASPX ')
INSERT INTO #TMPA VALUES (2, 'PSP ')
INSERT INTO #TMPA VALUES (3, 'JSP ')
CREATE TABLE #TMPB
(GUID varchar(40),
CID int,
GID int)
INSERT INTO #TMPB VALUES ( '1111 ',1,2)
INSERT INTO #TMPB VALUES ( '2222 ',2,3)
SELECT * FROM #TMPA
SELECT * FROM #TMPB
SELECT GUID, C.[NAME] AS CID, G.[NAME] AS GID
FROM #TMPB
JOIN #TMPA C ON #TMPB.CID=C.ID
JOIN #TMPA G ON #TMPB.GID=G.ID
DROP TABLE #TMPA
DROP TABLE #TMPB
------解决方案--------------------恭喜
------解决方案--------------------运行结果
1111 ASPX PSP
2222 PSP JSP
------解决方案--------------------顶下,也接点分
------解决方案--------------------接分
------解决方案--------------------前排支持,努力升星中
------解决方案--------------------向ezhuyin(碧海蓝天) 学习
jf
------解决方案--------------------接点分
------解决方案--------------------jf
------解决方案--------------------select guid,(select name from A where id=B.cid) as cname,(select name from A where id=B.gid) as gname from b
------解决方案--------------------接分
------解决方案--------------------接分
------解决方案--------------------j100f
------解决方案--------------------select b.guid,(select name from a where a.id=b.cid) as CID, (select name from a where a.id=b.gid) as GID from b
------解决方案--------------------select b.guid,a1.name as cname ,a2.name as gname from b left join a a1 on b.cid=a1.id left join a a2 on b.gid=a2.id
也可
------解决方案--------------------恭喜
------解决方案--------------------恭喜,接分
------解决方案--------------------接。。。。。。分。。。。。。了。。。
------解决方案--------------------select t1.guid,t2.name cname,t3.name gname from tableB t1