Created
April 23, 2012 21:52
-
-
Save mwilc0x/2474154 to your computer and use it in GitHub Desktop.
Merging two SQL queries into one
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
| I want to divide the correct count by total count (where the domain names match) | |
| /* Get the total count */ | |
| SELECT DISTINCT(domain_name), COUNT(*) AS count | |
| FROM recommendations | |
| WHERE rec_date LIKE '2007%' | |
| GROUP BY domain_name | |
| ORDER BY count DESC; | |
| /* Get the correct count */ | |
| SELECT DISTINCT(domain_name), COUNT(*) AS count | |
| FROM recommendations | |
| WHERE rec_date LIKE '2007%' AND direction = 'positive' AND adj_ret1d > 0 | |
| OR rec_date LIKE '2007%' AND direction = 'negative' AND adj_ret1d < 0 | |
| GROUP BY domain_name | |
| ORDER BY count DESC; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment