求一SQL语句,对于你来说可能不难!:)
有三个表(括号内为含有的字段): table1(mancode,scode)
,table2(scode,name),table3(ccode,scode,weight)
关联方式:table1.scode=table2.scode=table3.scode
现要统计:以mancod为分组的,scode 有多少。
即: select mancode,count(scode) as numbers from table1 group by
mancode
输出结果: mancode numbers
张三 30
李四 12
。 。
以scode 为分组的,ccode 有多少。
即: select scode,count(cccode) as numberc from table2 inner join
table3 on table2.scode=table3.scode group by scode
输出结果: scode numberc
1s002 16
1b002 164
。 。
其中有可能 mancode 的numbers 可能包括(1s002,1b002.....)
我现在要的结果是:
mancode,numbers,sumnumberc
张三 30 180
李四 12 378
。 。
不知道我描述的是否清楚,总之如有看懂的请帮忙,万分感谢!
在线等。。。。。。