这是一个示例表 CALLRECORD:
+--------+------------+
|callid | rating |
|1 | |
|2 | 5 |
|3 | |
|4 | 1 |
|5 | |
+--------+------------+
Run Code Online (Sandbox Code Playgroud)
输出总通话数、评级通话数、平均评级和未评级通话数没有问题:
select count(*) as total from callrecord;
select count(*) as rated, avg(rating) as average_rating from callrecord where rating is not null;
select count(*) as unrated from callrecord where rating is null;
Run Code Online (Sandbox Code Playgroud)
+--------+
|total |
|5 |
+--------+
+--------+------------+
|rated |average |
|2 |3 |
+--------+------------+
+--------+
|unrated |
|3 |
+--------+
Run Code Online (Sandbox Code Playgroud)
我正在寻找如何使用单个 SQL 请求将以上所有内容输出到一行:
+--------+--------+------------+---------+ …Run Code Online (Sandbox Code Playgroud)