我在一个表中有两列。表名是用inner join和group by构造的,我们称之为表Joined
。它有两列Present
和Score
。如果Present
是 null 那么,我想将 0 分配给该Score
值。
+------------+--------+-------------+------------+--------+
| Student_Id | Course | ExamDate | Present | Score |
+------------+--------+-------------+------------+--------+
| 1 | Math | 04/05/2020 | Yes | 45 |
| 2 | Math | 04/05/2020 | NULL | 90 |
| 2 | Math | 04/05/2020 | NULL | 50 |
+------------+--------+-------------+------------+--------+
我现在所拥有的是
SELECT DISTINCT StudentID ,Course, ExamDate, Present, Score
CASE Present ISNULL
Score = 0
END
FROM Joined
我需要不同的,因为内部连接可以给我一些重复。我需要的是
+------------+--------+-------------+------------+--------+
| Student_Id | Course | ExamDate | Present | Score |
+------------+--------+-------------+------------+--------+
| 1 | Math | 04/05/2020 | Yes | 45 |
| 2 | Math | 04/05/2020 | NULL | 0 |
+------------+--------+-------------+------------+--------+
这对我来说感觉非常非常错误,但我无法通过一个查询弄清楚如何做到这一点。我该怎么做?