eid name
1 john
2 pal
3 mike
4 michel
id eid mobile address
1 1 9640253265
2 2 9632587412 hellpp
3 3 poplop
4 4 9638523690
5 1 9632589632
6 2 addr
如何获得以下输出
name mobilecount addresscount
john 2 0
pal 1 2
mike 0 1
michel 1 0
答案 0 :(得分:2)
这样的事情:
COUNT
上述查询取决于NULL
不计算swift
值的函数。
答案 1 :(得分:0)
也许这会有所帮助。
select name,SUM(mobilecount) as mobilecount,SUM(addresscount) as addresscount
from
(
select t1.name,
case when isnull(t2.mobile,'')<>'' then count(mobile) else 0 end as
mobilecount,
case when isnull(t2.address,'')<>'' then count(mobile) else 0 end as
addresscount
from table1 t1,table2 t2
where t1.eid = t2.eid
group by t1.name,t2.mobile,t2.address
)employee
group by name order by name