0

単一の mysql クエリで、すべての列の値の合計の値を含む新しい行を合計として次のクエリに追加する必要があります。私を助けてください

SELECT username,enddt,SUM(zerotothirty) AS 0To30,
SUM(thirtytosixty) AS 31To60,SUM(sixtytoonetwenty) AS 61To120,
SUM(onetwentytotwoforty) AS 121To240,SUM(greaterthantwoforty) AS '>240' 
FROM 
(SELECT username,DATE(enddt) AS enddt,tickid,
 IF(duration <=30, 1,0) zerotothirty,
 IF(duration BETWEEN 31 AND 60, 1,0) thirtytosixty,
 IF(duration BETWEEN 61 AND 120,1,0) sixtytoonetwenty,
 IF(duration BETWEEN 121 AND 240,1,0) onetwentytotwoforty,
 IF(duration >240,1,0) greaterthantwoforty
 FROM report)AS r
 GROUP BY username,DATE(enddt);
4

2 に答える 2

1

WITH ROLLUP修飾子を使用してGROUP BY:

GROUP BY username,DATE(enddt) WITH ROLLUP;

(あなたの場合、これは各ユーザー名の小計とすべての結果の合計を表示します)。

于 2012-05-11T06:58:01.897 に答える