Last active
December 17, 2015 19:49
-
-
Save blockjon/5662740 to your computer and use it in GitHub Desktop.
What sql query will produce the results set below using just a single table scan?
This file contains 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
What sql query will produce the results set below using just a single table scan? | |
animals | |
----------------- | |
| size | color | | |
----------------- | |
| big | red | | |
| small | red | | |
| small | green | | |
----------------- | |
Results set: | |
----------------- | |
| big | red | | |
----------------- | |
| 1 | 2 | | |
----------------- |
SELECT
SUM(IF(size='big', 1, 0)) AS big,
SUM(IF(color='red', 1, 0)) AS red
FROM animals
quick & dirty
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
select top 1 1 as big, 2 as red from animals