At first I had:
SELECT
COUNT(casestates.id) AS statustotal
, casestates.name AS statusname
FROM
cases
INNER JOIN casestates ON cases.casestateid = casestates.id
WHERE
cases.helpdeskid = 'ee98652e-9fdf-435e-b325-74e7189b6561'
AND casestates.name != 'closed'
GROUP BY
casestates.name
The return was:
-----------------------------------------
| statustotal | statusname |
-----------------------------------------
| 5 | New |
-----------------------------------------
| 18 | Open |
Know using Use the ROLLUP and IFNULL clauses:
SELECT
COUNT(casestates.id) AS statustotal
,IFNULL(casestates.name,"Total") AS statusname -- changed here
FROM
cases
INNER JOIN casestates ON cases.casestateid = casestates.id
WHERE
cases.helpdeskid = 'ee98652e-9fdf-435e-b325-74e7189b6561'
AND casestates.name != 'closed'
GROUP BY
casestates.name
WITH ROLLUP; -- changed here
The return is:
statustotal statusname
-----------------------------------------
| statustotal | statusname |
-----------------------------------------
| 5 | New |
-----------------------------------------
| 18 | Open |
Resources:
SELECT
COUNT(casestates.id) AS statustotal
, casestates.name AS statusname
FROM
cases
INNER JOIN casestates ON cases.casestateid = casestates.id
WHERE
cases.helpdeskid = 'ee98652e-9fdf-435e-b325-74e7189b6561'
AND casestates.name != 'closed'
GROUP BY
casestates.name
The return was:
-----------------------------------------
| statustotal | statusname |
-----------------------------------------
| 5 | New |
-----------------------------------------
| 18 | Open |
-----------------------------------------
| 14 | Solved |
-----------------------------------------| 14 | Solved |
Know using Use the ROLLUP and IFNULL clauses:
SELECT
COUNT(casestates.id) AS statustotal
,IFNULL(casestates.name,"Total") AS statusname -- changed here
FROM
cases
INNER JOIN casestates ON cases.casestateid = casestates.id
WHERE
cases.helpdeskid = 'ee98652e-9fdf-435e-b325-74e7189b6561'
AND casestates.name != 'closed'
GROUP BY
casestates.name
WITH ROLLUP; -- changed here
The return is:
statustotal statusname
-----------------------------------------
| statustotal | statusname |
-----------------------------------------
| 5 | New |
-----------------------------------------
| 18 | Open |
-----------------------------------------
| 14 | Solved |
-----------------------------------------| 14 | Solved |
| 37 | Total |
-----------------------------------------Resources:
No comments:
Post a Comment