select b.字段1,sum(isnull(字段2,0)) as 字段2,sum(case when isnull(字段3,'A')='B' then 1 else 0 end) as 字段3 from a,b where a.字段1=*b.字段1
海阔天空: sum(isnull(字段2,0)) 不加表名,只有字段名是不行的,加了表名,也不行
这个问题有两种解决方法,第一种是 select b.字段1,sum(isnull(字段2,0)) as 字段2,sum(case when isnull(字段3,'A')='B' then 1 else 0 end) as 字段3 from a,b where a.字段1=*b.字段1 group by a.字段1 需要GROUP BY 一下,使用case 是完全正确的 另一种方法是使用同名表,然后用每个表查出一个字段,有几个字段就需要用多少个表。
from a,b
where a.字段1=*b.字段1
sum(isnull(字段2,0)) 不加表名,只有字段名是不行的,加了表名,也不行
select b.字段1,sum(isnull(字段2,0)) as 字段2,sum(case when isnull(字段3,'A')='B' then 1 else 0 end) as 字段3
from a,b
where a.字段1=*b.字段1
group by a.字段1
需要GROUP BY 一下,使用case 是完全正确的
另一种方法是使用同名表,然后用每个表查出一个字段,有几个字段就需要用多少个表。