无法在我的桌子上选择不同的

时间:2014-09-08 19:13:37

标签: mysql sql select

如何从我的数据库中仅选择一些不接听某些呼叫的不同呼叫者? 例如:在此示例表中,我只想选择数字6666666(在2014-09-08 10:48:52)和5555555(在2014-09-08 11:52:10),因为他们没有回答没有延伸。 我试过

SELECT DISTINCT * from cdr WHERE disposition !='ANSWERED';

但这会返回没有字符串的所有内容' ANSWERED'在处置。 谁能帮我?谢谢!! 表样本:
http://i.stack.imgur.com/CKZsh.png

2 个答案:

答案 0 :(得分:3)

SELECT * 
from cdr t1
LEFT JOIN cdr t2 ON t1.SRC = t2.SRC  
      AND t1.Date = t2.Date
      AND t1.Disposition <> t2.Disposition
WHERE t1.disposition = 'NO ANSWER'
GROUP BY t1.Date, t1.SRC
HAVING COUNT(*) = 1;

答案 1 :(得分:1)

select date, src
from cdr
group by date, src
having sum(disposition = 'ANSWERED') = 0

在回复评论时,如果您需要其他列,我建议您加入上述结果。否则,mysql将为每个组中的不属于该组的列返回一个随机值。即。

select cdr.* from cdr join (
    select date, src
    from cdr
    group by date, src
    having sum(disposition = 'ANSWERED') = 0
) t1 on t1.date = cdr.date and t1.src = cdr.src