Difference between revisions of "MySQL"

Jump to navigation Jump to search
135 bytes added ,  08:36, 17 March 2011
→‎COUNT: Added GROUP BY example
(Added "Events")
(→‎COUNT: Added GROUP BY example)
Line 167: Line 167:
<source lang="mysql">
<source lang="mysql">
SELECT COUNT(*) FROM hware WHERE make='IBM';                                                  # Counts number of rows in selection
SELECT COUNT(*) FROM hware WHERE make='IBM';                                                  # Counts number of rows in selection
SELECT make, COUNT(*) AS count FROM hware GROUP BY make;                                      # Counts number of occurrences of 'make'
SELECT COUNT(*) AS total, SUM(IF(model='x336',1,0)) AS x336 FROM hware WHERE make='IBM';      # Additional counts number of rows where model='x336'
SELECT COUNT(*) AS total, SUM(IF(model='x336',1,0)) AS x336 FROM hware WHERE make='IBM';      # Additional counts number of rows where model='x336'
</source>
</source>

Navigation menu