简体   繁体   English

从与其他列分组的MySql表列中获取唯一值

[英]Get unique values from a MySql table column grouped with other column

This might be a very basic query practice for MySql experts, but I can't get a result as I'm expecting. 对于MySql专家来说,这可能是一个非常基本的查询实践,但是我没有得到预期的结果。

Below is the MySql query and the output pane. 下面是MySql查询和输出窗格。 What I want to achieve is to get the bug_ids which is not present in the records for all cell_ids. 我要实现的是获取bug_ids,该bug_ids不在所有cell_ids的记录中。 In other words, looking at the records below we can see bug_ids 1,2,3,4 are present for all cell_ids 32,33,34. 换句话说,查看下面的记录,我们可以看到对于所有cell_id 32、33、34,都存在bug_id 1、2、3、4。 I want the records other than these bug_ids. 我想要这些bug_id以外的记录。 So the expected output would be something like this, 因此,预期的输出将是这样的,

project_id cell_id bug_id test_set_id case_id  
106        32      16     1           5  
106        33      16     1           5  
106        34       7     1           5  

I have also tried using self join but couldn't found a proper query. 我也尝试使用自连接,但找不到正确的查询。

查询输出

Please let me know if you need more info. 如果您需要更多信息,请告诉我。 Any help will be greatly appreciated. 任何帮助将不胜感激。 Thanks guys. 多谢你们。

You can get the list of bugs that are not in all the cells by doing: 您可以通过执行以下操作获取并非所有单元中的错误的列表:

select bug_id
from tran_cell_bug tcb
where cell_id in (32, 33, 34)
group by bug_id
having count(distinct cell_id) <> 3;

You can then use join to get the original values: 然后,您可以使用join来获取原始值:

select tcb.*
from tran_cell_bug tcb join
     (select bug_id
      from tran_cell_bug tcb
      where cell_id in (32, 33, 34)
      group by bug_id
      having count(distinct cell_id) <> 3
     ) b
     on tcb.bug_id = b.bug_id;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM