【发布时间】:2019-04-28 14:22:07
【问题描述】:
我有一张这样的表格(大大简化了):
|student_id|Courses| grades |
+----------+-------+--------+
| 001 | Math | 95 |
| 001 | Math | 83 |
| 001 | Others| 33 |
| 002 | Math | 92 |
| 002 | Others| 12 |
| 002 | Others| 72 |
我想要什么:
- “数学”计数
- “其他”的最小值
- 按 student_id 分组
期望的结果:
|student_id|Num_math|min_others|
+----------+--------+----------+
| 001 | 2 | 33 |
| 002 | 1 | 12 |
【问题讨论】:
-
提示:
GROUP BY、COUNT()、CASE。 -
或者,this one,但想法是一样的。
标签: sql sql-server tsql aggregate-functions