select a.字段,a.a,a.b,a.c,a.d,a.e from table a, table b where a.a=b.a and a.b=b.b and a.c=b.c and a.字段<>b.字段这个样子?
取出A,B,C字段有相同值的记录SELECT t1.* FROM aTable t1 INNER JOIN ( SELECT A, B, C FROM aTable GROUP BY A, B, C HAVING COUNT(*) > 1 ) t2 ON t2.A = t1.A AND t2.B = t1.B AND t2.C = t1.C
你们误会了现在要取出记录1、2、3、5 字段 :a b c d e 记录1:1 2 3 4 5 记录2: 1 2 3 5 6 记录3: 1 2 3 7 8 记录4:2 1 3 5 3 记录5:1 2 3 8 9
a字段 和 b 字段 c字段本身值相同
没问题啊,就可以用这个取啊 select * from yourtable where A=B and A=C你没说明白
这个问题不时这么简单只有 haoK(haoK.Y) 理解了
那haoK(haoK.Y)的是对的了啊 --测试数据 create table yourtable(a int,b int,c int,d int,e int)insert yourtable select 1 , 2 , 3 , 4 , 5 union all select 1 , 2 , 3 , 5 , 6 union all select 1 , 2 , 3 , 7, 8 union all select 2 ,1 , 3 , 5 , 3 union all select 1 , 2 , 3, 8 , 9 SELECT t1.* FROM yourtable t1 INNER JOIN ( SELECT A, B, C FROM yourtable GROUP BY A, B, C HAVING COUNT(*) > 1 ) t2 ON t2.A = t1.A AND t2.B = t1.B AND t2.C = t1.C
select t1.* from yourtable t1,(select a,b,c from yourtable group by a,b,c having count(*)>1) t2 where t1.a=t2.a and t1.b=t2.b and t1.c=t2.c 还可以这样写吧
first: create yourview from yourtable secord: inner join yourtable and yourview third: where.
select yourtable.* from yourtable t1,(select A,B,C from yourtable group by A,B,C having count(A)=count(B) and count(B)=count(C) ) t2 where t1.A=t2.A and t1.B=t2.B and t1.C=t2.C
from table a, table b
where a.a=b.a and a.b=b.b and a.c=b.c and a.字段<>b.字段这个样子?
FROM aTable t1
INNER JOIN (
SELECT A, B, C
FROM aTable
GROUP BY A, B, C
HAVING COUNT(*) > 1
) t2 ON t2.A = t1.A
AND t2.B = t1.B
AND t2.C = t1.C
记录1:1 2 3 4 5
记录2: 1 2 3 5 6
记录3: 1 2 3 7 8
记录4:2 1 3 5 3
记录5:1 2 3 8 9
select * from yourtable where A=B and A=C你没说明白
--测试数据
create table yourtable(a int,b int,c int,d int,e int)insert yourtable select 1 , 2 , 3 , 4 , 5
union all select 1 , 2 , 3 , 5 , 6
union all select 1 , 2 , 3 , 7, 8
union all select 2 ,1 , 3 , 5 , 3
union all select 1 , 2 , 3, 8 , 9
SELECT t1.*
FROM yourtable t1
INNER JOIN (
SELECT A, B, C
FROM yourtable
GROUP BY A, B, C
HAVING COUNT(*) > 1
) t2 ON t2.A = t1.A
AND t2.B = t1.B
AND t2.C = t1.C
还可以这样写吧
first: create yourview from yourtable
secord: inner join yourtable and yourview
third: where.
from yourtable t1,(select A,B,C from yourtable group by A,B,C having count(A)=count(B) and count(B)=count(C) ) t2
where t1.A=t2.A and t1.B=t2.B and t1.C=t2.C