Created
June 23, 2009 22:49
-
-
Save hobodave/134899 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| Submitter, | |
| SUM( CASE col WHEN '0' THEN data ELSE 0 END ) AS 'Bad', | |
| SUM( CASE col WHEN '2004' THEN data ELSE 0 END ) AS '2004', | |
| SUM( CASE col WHEN '2005' THEN data ELSE 0 END ) AS '2005', | |
| SUM( CASE col WHEN '2006' THEN data ELSE 0 END ) AS '2006', | |
| SUM( CASE col WHEN '2007' THEN data ELSE 0 END ) AS '2007', | |
| SUM( CASE col WHEN '2008' THEN data ELSE 0 END ) AS '2008', | |
| SUM( CASE col WHEN '2009' THEN data ELSE 0 END) AS '2009', | |
| SUM( data ) AS Total | |
| FROM ( | |
| SELECT | |
| CONCAT(firstname, ' ', lastname) AS 'Submitter', | |
| YEAR(created) AS 'col', | |
| COUNT(*) AS data | |
| FROM users u | |
| JOIN tickets t ON u.id = t.submitter_id | |
| GROUP BY u.id, YEAR(t.created) | |
| ) AS stats | |
| GROUP BY submitter WITH ROLLUP; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +-------------------------+------+------+------+------+------+------+------+--------+ | |
| | Submitter | Bad | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | Total | | |
| +-------------------------+------+------+------+------+------+------+------+--------+ | |
| ... snip ... | |
| | Susan Massatt | 0 | 0 | 3 | 2 | 0 | 0 | 0 | 5 | | |
| | Susan Wilson | 0 | 0 | 6 | 0 | 0 | 0 | 0 | 6 | | |
| | Wendy Ambrose-Gavin | 0 | 0 | 0 | 0 | 2 | 0 | 0 | 2 | | |
| | Willie Jackson | 0 | 0 | 0 | 0 | 4 | 74 | 0 | 78 | | |
| | NULL | 1 | 17847 | 44304 | 35796 | 24412 | 33700 | 13486 | 169546 | | |
| +-------------------------+------+-------+-------+-------+-------+-------+-------+--------+ | |
| 57 rows in set (1.28 sec) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| SELECT | |
| IFNULL( submitter, 'SUMS') AS Submitter, Bad, 2004, 2005, 2006, 2007, 2008, 2009, Total | |
| FROM ( | |
| SELECT | |
| Submitter, | |
| SUM( CASE col WHEN '0' THEN data ELSE 0 END ) AS 'Bad', | |
| SUM( CASE col WHEN '2004' THEN data ELSE 0 END ) AS '2004', | |
| SUM( CASE col WHEN '2005' THEN data ELSE 0 END ) AS '2005', | |
| SUM( CASE col WHEN '2006' THEN data ELSE 0 END ) AS '2006', | |
| SUM( CASE col WHEN '2007' THEN data ELSE 0 END ) AS '2007', | |
| SUM( CASE col WHEN '2008' THEN data ELSE 0 END ) AS '2008', | |
| SUM( CASE col WHEN '2009' THEN data ELSE 0 END) AS '2009', | |
| SUM( data ) AS Total | |
| FROM ( | |
| SELECT | |
| CONCAT(firstname, ' ', lastname) AS 'Submitter', | |
| YEAR(created) AS 'col', | |
| COUNT(*) AS data | |
| FROM users u | |
| JOIN tickets t ON u.id = t.submitter_id | |
| GROUP BY u.id, YEAR(t.created) | |
| ) AS stats | |
| GROUP BY submitter WITH ROLLUP | |
| ) AS stats2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| +-------------------------+------+------+------+------+------+------+------+--------+ | |
| | Submitter | Bad | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | Total | | |
| +-------------------------+------+------+------+------+------+------+------+--------+ | |
| ... snip ... | |
| | Susan Massatt | 0 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 5 | | |
| | Susan Wilson | 0 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 6 | | |
| | Wendy Ambrose-Gavin | 0 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 2 | | |
| | Willie Jackson | 0 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 78 | | |
| | SUMS | 1 | 2004 | 2005 | 2006 | 2007 | 2008 | 2009 | 169546 | | |
| +-------------------------+------+------+------+------+------+------+------+--------+ | |
| 57 rows in set (1.58 sec) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment