У меня есть сценарий MySQL для сводной таблицы, а затем подсчитываю некоторые данные внутри:
SELECT A.Line,
week1.1stweek, week2.2ndweek,
IFNULL(week1.1stweek,0) + IFNULL(week2.2ndweek,0) AS TOTAL
FROM inspection_report AS A
LEFT JOIN(
SELECT Line, (SUM(S) + SUM(A) + SUM(B)*0.4 + SUM(C)*0.1)/COUNT(Serial_number) AS 1stweek
FROM inspection_report
WHERE DAY(Inspection_datetime) BETWEEN 1 AND 7
GROUP BY Line, WEEK(Inspection_datetime), YEAR(Inspection_datetime)
) AS week1 USING (Line)
LEFT JOIN(
SELECT Line, (SUM(S) + SUM(A) + SUM(B)*0.4 + SUM(C)*0.1)/COUNT(Serial_number) AS 2ndweek
FROM inspection_report
WHERE DAY(Inspection_datetime) BETWEEN 8 AND 14
GROUP BY Line, WEEK(Inspection_datetime), YEAR(Inspection_datetime)
) AS week2 USING (Line)
GROUP BY Line
заставляет заголовок таблицы показывать кнопку «Мне нравится».
после этого я хочу сделать «СУММУ» под каждым столбцом, как:
Line 1stweek 2ndweek total
1 12 2 14
2 3 0 3
SUM 15 2 17
как мне это сделать?