表结构如下:
mysql> select * from dup_view;
+---------+----------+----------+-----------+
| call_id | s_msisdn | o_msisdn | o_call_id |
+---------+----------+----------+-----------+
|       1 |   123456 |   654321 |         2 |
|       2 |   654321 |   123456 |         1 |
|       3 |    98765 |   567890 |         4 |
|       4 |   567890 |    98765 |         3 |
|       5 |   123456 |   999999 |         0 |
+---------+----------+----------+-----------+
5 rows in set (0.00 sec)如何写查询语句取出表中没有重复的记录,重复的记录是指call_id和o_call_id相互相等的两条记录。如 1和2, 3和4。期望的查询结果是1,3,5。

解决方案 »

  1.   

    try:
    select * from tt a where not exists(select 1 from tt where a.call_id=o_call_id  and a.call_id=o_call_id )
    union all
    select * from tt a where not exists(select 1 from tt where a.call_id=o_call_id  and a.call_id=o_call_id and a.call_id>call_id)
      

  2.   

    估计重复的记录取最小的call_id
      

  3.   

    楼主何苦这么纠结....看了你的数据总结出一个规律....
    call_id < s_msisdn 字段的值成立么?
    若是成立的话,就很简单了,我就不写出来了... = =
      

  4.   

    如果都是成对记录的话,则直接如下即可。select * from dup_view where s_msisdn<o_msisdn;
      

  5.   

    or
    select * from tt a where not exists(select 1 from tt where a.call_id=o_call_id and a.call_id=o_call_id and a.call_id>call_id)