日期:2014-05-20  浏览次数:20851 次

求sql语句
access数据库

员工表:yg
ID     ygNAME     price
1         a君       1222
2         b君       1300
3         c君       3000
4         d君       3050
5         e君       3050
6         f君       3080

员工部门表:ygbm
ID     ygNAME           bm
1         a君               it
2         b君               it
3         c君               sale
4         d君               sale
5         e君               it
6         f君               sale

部门表:bm
ID     bmNAME
1         it
2         sale

得出结果
ID     bm           sumprice
1       it           6500
2       sale       7800

------解决方案--------------------
select bm,sum(price) sumprice
from yg,ygbm
where yg.ygname=ygbm.ygname
group by bm
------解决方案--------------------
select y.bmid,y.bmname,sum(y.price) from (select bm.id as bmid,bm.bm as bmname,yg.price as price from yg,ygbm,bm where yg.ygname = ygbm.ygname and bm.bm = ygbm.bm) y group y.bmname
------解决方案--------------------
select abm,sum(aprice) from (select ygbm.bm as abm,yg.price as aprice from ygbm inner join yg on ygbm.ygName=yg.ygName) a group by bm
------解决方案--------------------
随便写了下,没测试:
select bm.id,bm.bmNAME,a.sumprice from bm left OUTER JOIN
(
select ygbm.bm,sum(yg.price) as sumprice from yg left OUTER JOIN ygbm on yg.id=ygbm.id group by ygbm.bm
) a
on bm.bmNAME=a.bm
------解决方案--------------------
你的工资是不是自已算错了
------解决方案--------------------
SELECT T1.bmNAME,SUM(T3.price)
FROM bm T1
LEFT JOIN ygbm T2 ON T1.bmNAME = T2.bm
LEFT JOIN yg T3 ON T2.ygNAME = T3.ygNAME
GROUP BY T1.id,T1.bgName
------解决方案--------------------
sskset(断点) is right!