select a.id,isnull(b.counts,0) as isnum
from
p_cond as a
left join
(select p_cond_id,count(*) as counts from p_cond_han group by p_cond_id) as b
on a.id=b.p_cond_id
sqlserver用上边写法
mysql把isnull换成ifnull
oracle把isnull换成nvl
select a.id,isnull(b.counts,0) as isnum
from
p_cond as a
left join
(select p_cond_id,count(*) as counts from p_cond_han group by p_cond_id) as b
on a.id=b.p_cond_id
sqlserver用上边写法
mysql把isnull换成ifnull
oracle把isnull换成nvl