test_id test_context
1 A
2 B
5 O
3 J
5 K
3 C
5 O
如上方,是一张表,我要怎么写查询语句选出test_id有重复的记录且test_context不同的记录要保留,剔除test_id无重复和test_id重复且test_context相同的记录。查询结果如:
test_id test_context
3 C
3 J
5 K
5 O
查询语句怎么写呢?表的记录有35多万条,考虑高效。有大神能帮忙吗?重赏
...全文
69364打赏收藏
mysql 查询表中字段值相同的记录
test_id test_context 1 A 2 B 5 O 3 J 5 K 3 C 5 O 如上方,是一张表,我要怎么写查询语句选出test_id有重复的记录且test_context不同的记录要保留,剔除test_id无重复和test_id重复且test_context相同的记录。查询结果如: test_id test_context 3 C 3 J 5 K 5 O 查询语句怎么写呢?表的记录有35多万条,考虑高效。有大神能帮忙吗?重赏
select distinct t1.* from t1,(select test_id from t1 group by test_id having count(distinct test_context)>1) t2 where t1.test_id=t2.test_id order by test_id;