子查询的值多于一个的问题
这样写有什么毛病啊 怎么改啊
select
,c21.a0190
,SUM(select case when right(c105.gz_ym,2)= '01 ' then isnull(c10511,0) else 0 end from c105,c21 where c105.a0188=c21.a0188 and c105.gz_ym=c21.gz_ym) as '一月 '
from c21,deptcode,c105
where c21.dept_id=deptcode.dept_id
SUM函数 是不是不能这么用?去了SUM出现子查询的值多于一个
------解决方案--------------------这样?
select
c21.a0190,
SUM(case when right(c105.gz_ym,2)= '01 ' then isnull(c10511,0) else 0 end) as '一月 '
from c21
join c105
on c105.a0188=c21.a0188 and c105.gz_ym=c21.gz_ym
join deptcode
on c21.dept_id=deptcode.dept_id
group by c21.a0190
------解决方案--------------------select
,c21.a0190
,SUM(case when right(c105.gz_ym,2)= '01 ' then isnull(c10511,0) else 0 end ) as '一月 '
from c21,deptcode,c105
where c21.dept_id=deptcode.dept_id and c105.a0188=c21.a0188 and c105.gz_ym=c21.gz_ym