常用SQL


常用SQL

1.查找表中单个字段的值有哪些相同的记录:

假设表名是table,列名是column,则查询语句为:

SELECT * FROM table WHERE column IN (SELECT column FROM table GROUP BY column HAVING COUNT(column)>1)

2.查找表中多个字段的值有哪些相同的记录:

假设表名是table,列名是column1,列名column2,则查询语句为:

SELECT A.* FROM table A RIGHT JOIN (SELECT column1,column2 FROM table group by column1,column2 HAVING COUNT(*)>1 )  B ON A.column1 = B.cloumn1 AND A.column2 = B.column2

声明:Sigma|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 常用SQL


附着于石,取些皮毛