简体   繁体   English

MySQL:检查组中的值

[英]MySQL: Check if value within group

I have a database with races in. I want to check to see if within a group a column contains a value. 我有一个包含种族的数据库。我想检查一下是否在组中一列包含一个值。

So something like: 所以像这样:

SELECT count(*) as total 
FROM table 
WHERE column contains value 'hurdal' 
   OR column contains value 'chase' 
GROUP BY column

Then I can see how many contain that value within the group. 然后,我可以看到在该组中有多少包含该值。

select count(*) as total from table where column in ('hurdal', 'chase') group by column

IN checks the column value is contained within the group specified, thus this will match any row where column is either hurdal or chase . IN检查列值包含所指定的组中,从而将匹配的任何行,其中column是任一hurdalchase

For more information, the MySQL specific documentation is here , but this is a standard SQL operator so should work on any DBMS. 欲了解更多信息,MySQL的具体文件是在这里 ,但是这是一个标准的SQL运营商等都应该在任何DBMS工作。

In MySQL for checking contain you need LIKE operator, Like this: 在MySQL中检查是否包含LIKE运算符,如下所示:

SELECT count(*) as total 
FROM table 
WHERE column LIKE '%hurdal%' 
   OR column LIKE '%chase%' 
GROUP BY column

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

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