思路话语

。Arlen:思想有多远你就能走多远...

where group by having

普通用法:
如找出有sn重复的行
select * from t_device where isdel=0 group by sn having count(sn)>1

也有些复杂的场景:
找没有逻辑区域的机房:
select t_idc.id,t_idc.name from t_idc left join idc_safedomain on t_idc.id=idc_safedomain.idc_id group by t_idc.id having count(idc_safedomain.id)=0;

这时候如果用count(*)就找不出:
select t_idc.id,t_idc.name from t_idc left join idc_safedomain on t_idc.id=idc_safedomain.idc_id group by t_idc.id having count(*)=0;

posted on 2008-09-11 09:46  Arlen  阅读(521)  评论(0编辑  收藏  举报

导航