求最优SQL语句
表:
字段1 字段2
1 ABCDEF
1 CDWERT
2 ACDEFG
2 BCDSER
3 BCDEFH
3 ABCDWS
3 YTEBCS
4 FESGTD
4 UTESDW
5 TRSBCW
5 ABVDSW
5 FGTBCE
需要统计字段2中包含BC的,而且记录两次以上的字段1
根据上表结构:3,5
求此SQL的最优语句
------解决方案--------------------select * from csdn_test
where name like '%BC% ' and
exists (select id,count(id) from csdn_test t
where t.id=csdn_test.id group by id having count(id)> 2);