请问各位一个sql简单的问题?
已知有一个表t1:name,code,grade,no
t2:code,salary
输出:t3的结果如下-》
grade code name salary
A 1 wang 1000$
A 2 li 2000$
total 3000$
B 3 zhang 1000$
B 4 shan 2000$
total 3000$
grant 6000$
请问怎样用SQL得到T3这样的报表输出格式呢?
问题点数:30、回复次数:4Top
1 楼Frewin(frewin)回复于 2005-07-01 14:45:04 得分 0
Select t1.* from,t2.salary From t1 Where t1.code=t2.code
union all
Select '','',sum(salary) From t2 Group By CodeTop
2 楼colorbird(可可改改)回复于 2005-07-01 14:50:52 得分 0
谢谢你的回答,但还是有点问题不能实现?请再写清楚点么
他这里对每一个组都实行了SUM呢,而且最后对SALARY有总的统计呢
Top
3 楼wwwwb()回复于 2005-07-01 14:56:59 得分 0
Select t1.* from,t2.salary From t1 Where t1.code=t2.code
union all
Select '','',sum(salary) From t2 Group By Code
union all
Select '','',sum(salary) as salary From (select sum(salary) as salary From t2
Group By Code) dd
Top
4 楼colorbird(可可改改)回复于 2005-07-01 15:21:27 得分 0
好像还是不行呢,谢谢。。。。。。。Top




