Created
March 20, 2015 11:52
-
-
Save daynebatten/b54a2db4caee735965f9 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
| create temp table guesses as | |
| select | |
| t.first_name, | |
| t.middle_name, | |
| t.last_name, | |
| t.name_suffix, | |
| t.gender, | |
| case when | |
| case when f.male_score is null then 0 else f.male_score end + case when m.male_score is null then 0 else m.male_score end + case when s.male_score is null then 0 else s.male_score end | |
| > | |
| case when f.female_score is null then 0 else f.female_score end + case when m.female_score is null then 0 else m.female_score end + case when s.female_score is null then 0 else s.female_score end | |
| then | |
| 'M' | |
| else | |
| 'F' | |
| end as guessed_gender | |
| from | |
| test as t | |
| left join first_scores as f on f.first_name = t.first_name | |
| left join middle_scores as m on m.middle_name = t.middle_name | |
| left join suffix_scores as s on s.name_suffix = t.name_suffix; | |
| /* Calculate percent we got right */ | |
| select | |
| cast(sum(case when gender = guessed_gender then 1 else 0 end) as float) / cast(count(*) as float) | |
| from | |
| guesses; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment