我有以下查詢:集團集團在SQL
SELECT Inspections.Pipe_Segment_Reference,
(COUNT(*) * Conditions.structural_grade) AS Structural_Rating
FROM (
SELECT Inspections.Pipe_Segment_Reference, Conditions.structural_grade
FROM Conditions
INNER JOIN Inspections
ON Conditions.InspectionID = Inspections.InspectionID
WHERE Conditions.structural_grade IS NOT NULL
)
GROUP BY Inspections.Pipe_Segment_Reference, Conditions.structural_grade;
,輸出
22, 2
22, 4
79, 2
79, 5
79, 3
我想通過Pipe_Segment_Reference進一步GROUP獲得的
22, 6
79, 10
我試圖輸出在上面的查詢中添加一個額外的選擇,但我無法讓它工作。
查詢運行,但不輸出正確的值作爲需要被包括查詢的該部分:(COUNT(*)* Conditions.structural_grade)AS Structural_Rating –