select * from x where 字段A=“你要查的值” 比如 表名:table 字段 A B 1 2 1 3 2 4select * from table where a=1就把第一条和第二条查出来了
select * from x where a in (select a from x group by a having count(a)>1)
我的方法很笨,但可以实现: table2: id name 1 as 2 as 3 g 4 k 5 g 下面是sql: select (case count(name) when 1 then null else name end) as rname into temp from table2 group by nameselect * from table2 where name in(select rname from temp)drop table temp ------------------测试结果——------------- 1 as 2 as 3 g 5 g ----------------------------------- (所影响的行数为 3 行) (所影响的行数为 4 行)
select * from x join (select a from x group by a having count(a)>1) b on x.a=b.a
按字段A進行分組就可以了 SELECT A,..... FROM 表 GROUP BY A,.....
select * from x where a in (select a from x group by a having count(a)>1)
select * from x where a in (select a from x group by a having count(a)>1) order by a
where 字段A=“你要查的值”
比如
表名:table
字段
A B
1 2
1 3
2 4select *
from table
where a=1就把第一条和第二条查出来了
table2:
id name
1 as
2 as
3 g
4 k
5 g
下面是sql:
select
(case count(name) when 1 then null else name end) as rname into temp
from table2
group by nameselect * from table2 where name in(select rname from temp)drop table temp
------------------测试结果——-------------
1 as
2 as
3 g
5 g
-----------------------------------
(所影响的行数为 3 行)
(所影响的行数为 4 行)
on x.a=b.a
SELECT A,..... FROM 表
GROUP BY A,.....
where a in (select a from x group by a having count(a)>1)
order by a