嗨,我有查询返回我的数据

SELECT
     s.StandardID,
     s.StandardName as Standard,
     TableA.Score,
     Dropdown1.Name as dq,
     Standard.ParentStandardID,
     Standard.Weight
FROM TableA
      JOIN Standard ON Standard.StandardID = TableA.StandardID


结果

+------------+----------+-------+------------------+---------+
| StandardID | Standard | Score | parentstandardid |  weight |
+------------+----------+-------+------------------+---------+
|    1       |     A    |       |      3           |    o    |
+------------+----------+-------+------------------+---------+
|   107      |     B    |       |     NULL         |    1    |
+------------+----------+-------+------------------+---------+
|   111      |     C    |       |      1           |   107   |
+------------+----------+-------+------------------+---------+
|   112      |     D    |       |      2           |   107   |
+------------+----------+-------+------------------+---------+


现在,分数为空,我想显示核心响应父母ID的分数总和。如果standardID为107,且比null得分高的分数应该是父母ID的总和107。如果不比得分高,则不使用任何分组依据。

任何帮助,将不胜感激
谢谢 !

最佳答案

选择

S.StandardID,
  (当A.Score为NULL则C.Score ELSE A.Score结束的情况)AS New_Score

从表A

内联接标准S ON S.StandardID = TableA.StandardID
左外连接

 SELECT S1.ParentStandardID,SUM(B.ScoreValue)得分
 在表B中,标准S1,其中S1.StandardID = B.StandardID
 GROUP BY ParentStandardID
) C
开启S.StandardID = C.ParentStandardID

09-27 04:00