一个表中有paid,schoolsupm,family,babc四个字段,查询同时参加4个/3个/2个/1个/ 的个数 用sql语句
时间: 2023-08-16 09:08:07 浏览: 111
可以使用以下 SQL 语句实现:
同时参加四个的个数:
```
SELECT COUNT(*) FROM 表名 WHERE paid = 'yes' AND schoolsupm = 'yes' AND family = 'yes' AND babc = 'yes';
```
同时参加三个的个数:
```
SELECT COUNT(*) FROM 表名 WHERE (paid = 'yes' AND schoolsupm = 'yes' AND family = 'yes') OR (paid = 'yes' AND schoolsupm = 'yes' AND babc = 'yes') OR (paid = 'yes' AND family = 'yes' AND babc = 'yes') OR (schoolsupm = 'yes' AND family = 'yes' AND babc = 'yes');
```
同时参加两个的个数:
```
SELECT COUNT(*) FROM 表名 WHERE (paid = 'yes' AND schoolsupm = 'yes') OR (paid = 'yes' AND family = 'yes') OR (paid = 'yes' AND babc = 'yes') OR (schoolsupm = 'yes' AND family = 'yes') OR (schoolsupm = 'yes' AND babc = 'yes') OR (family = 'yes' AND babc = 'yes');
```
同时参加一个的个数:
```
SELECT COUNT(*) FROM 表名 WHERE paid = 'yes' OR schoolsupm = 'yes' OR family = 'yes' OR babc = 'yes';
```
其中,表名需要替换为实际的表名。同时注意,以上语句中的 yes 可能需要根据实际情况替换为其他值。
阅读全文