首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求个sql语句,该如何处理

2012-03-31 
求个sql语句tableA(intaid,stringaname)tableB(intbid,intcid,stringbname)tableC(intcid,stringcname)tab

求个sql语句
table   A(int   aid,string   aname)
table   B(int   bid,int   cid,string   bname)
table   C(int   cid,string   cname)
table   D(int   did,int   aid,int     bid)

表A,B,C,D第一列都是主键

求个sql语句
当did=XXX时
select出如下的行集
(did,aname,bname,cname)

[解决办法]
select d.did,a.aname,b.bname,c.cname from d
inner join a on d.aid=a.aid
inner join b on d.bid=b.bid
inner join c on c.cid=b.cid
[解决办法]
select D.bid,A.aname,T.bname,T.cname
from A,D,
(
select B.bid,B.bname,C.cname
from B,C
where B.cid=C.cid
) T
where A.aid=D.aid
and B.bid=D.bid

[解决办法]
select did,aname,bname,cname
from D
inner join A on D.aid=A.aid
inner join
(
select B.*,C.cname from B inner join C on B.cid=C.cid
)t
on D.bid=t.bid
=====================================
select did,sum(D.price),sum(t.price)
from D
inner join
(
select B.*,C.price from B inner join C on B.cid=C.cid
)t on D.bid=T.bid
where did=XXX
group by did
不知道要哪個price sum

热点排行