diff options
author | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-22 14:39:14 +0000 |
---|---|---|
committer | Yann Herklotz <ymherklotz@gmail.com> | 2017-02-22 14:39:14 +0000 |
commit | 52da5379460cb10cca067bbfc8e446b2fcb6395f (patch) | |
tree | f7e598ab070c714ab457c604130317eb360a19a6 | |
parent | 05abeebeb36cf81677ef20ab3918091dd01a078e (diff) | |
download | DatabaseCoursework-52da5379460cb10cca067bbfc8e446b2fcb6395f.tar.gz DatabaseCoursework-52da5379460cb10cca067bbfc8e446b2fcb6395f.zip |
-rw-r--r-- | db_2017_cw1.sql | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/db_2017_cw1.sql b/db_2017_cw1.sql index 3523f37..13f7be8 100644 --- a/db_2017_cw1.sql +++ b/db_2017_cw1.sql @@ -72,10 +72,21 @@ ORDER BY name -- Q7 returns (father,mother,child,born) - +SELECT father, mother, name AS child, + RANK() OVER (PARTITION BY father ORDER BY dob) as born +FROM person +WHERE father IS NOT NULL +AND mother IS NOT NULL +ORDER BY father, mother, born ; -- Q8 returns (father,mother,male) - +SELECT father, mother, + ROUND(100 * COUNT(CASE WHEN gender = 'M' THEN name ELSE NULL END) / COUNT(name), 0) as male +FROM person +GROUP BY father, mother +HAVING father IS NOT NULL +AND mother IS NOT NULL +ORDER BY father, mother ; |