日期:2014-05-17  浏览次数:20689 次

不同表链接count(表1)和sum(表2)函数结果集,急......
如题

------解决方案--------------------
SQL code

select count(distinct a.字段) as acount
from a inner join b on a.字段=b.字段

select sum(b.字段) as bsum
from a inner join b on a.字段=b.字段
group by b.字段

------解决方案--------------------
你算聚合函数那里连from都没有的?不抱错吗?
------解决方案--------------------
晕,这都能不报错?把你表结构给出来,最好给点数据吧。抽时间帮你谢谢select(select count(SubCode)from Speed
 where convert(varchar(7),BeginDate,120) = '2012-09' )as spCount,
 (select SUM(B.kiloDay)where convert(varchar(7),billdate,120) = '2012-09')as kiloSum,B.SubCode
 from Kilo B
 left join Speed A
 on A.SubCode = B.SubCode
 where convert(varchar(7),billdate,120) = '2012-09'
 group by B.SubCode,A.SubCode,convert(varchar(7),billdate,120)