简体   繁体   English

对另一个相似表中具有匹配值的记录进行分组,计数和排除

[英]Group, count, and exclude records with matching values in another similar table

Select Gender, Count(*)as TotalGender
FROM 1
Group by Gender

This works perfect for me. 这对我来说很完美。

However, this table(1) has a similar column to another table(2). 但是,此表(1)的列与另一个表(2)相似。

If this similar column has matching values, I need to exclude those values from the above count. 如果此相似列具有匹配值,则需要从上述计数中排除这些值。

Use a JOIN in that case, like this: 在这种情况下,请使用JOIN,如下所示:

SELECT Gender, 
       COUNT(*) AS TotalGender
FROM `1` 
LEFT JOIN `2`
     ON `1.somecolumn` = `2.somecolumn`
WHERE `2.somecolumn` IS NULL
GROUP BY Gender

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

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