
1.表Information中有四个字段:ID,Name,Sex,Position ID为主键,现在想查找姓名一样的记录,sql语句应该写为: select * from Information where Name in ( select Name from Information group by name having count(*)>1) 2.如果要查询姓名不同的记录,sql语句应该写为: select * from Information where Name not in ( select Name from Information group by name having count(*)>1) 3.如果是查询记录数,只要将上述语句中的* 改为count(*)或count(Name),其中count(Name)比count(*)的效率要高.

转载于:https://my.oschina.net/renyuansoft/blog/6918