我想同时运行两个 sql 查询,这样我就不必运行两次才能获得结果
SELECT COUNT(*) FROM attendance WHERE month =10 and grade = 4
SELECT COUNT(*) from attendance WHERE month = 10 and grade = 4 AND userid = 24 and attendance = 'present'
Run Code Online (Sandbox Code Playgroud)
我想要两个总班级数和学生出席的班级总数。
You can combine the second criteria using conditional aggregation, this way the table is only read once.
select
Count(*) as TotalCount,
Count(case when userid = 24 and attendance = 'present' then 1 end) as StudentCount
from attendance
where month = 10 and grade = 4;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |