四个select count 把这四个select count合并为一个select语句 分别显示count
时间: 2024-01-22 19:17:41 浏览: 112
可以使用UNION ALL将四个SELECT COUNT语句合并为一个SELECT语句,并分别显示COUNT的结果。示例代码如下:
```
SELECT COUNT(col1) AS count_col1 FROM table1
UNION ALL
SELECT COUNT(col2) AS count_col2 FROM table2
UNION ALL
SELECT COUNT(col3) AS count_col3 FROM table3
UNION ALL
SELECT COUNT(col4) AS count_col4 FROM table4;
```
这个查询语句将会返回包含四个行的结果集,每一行中都包含一个count值,分别代表了对应表中指定列的行数。
阅读全文