Created
February 25, 2021 15:14
-
-
Save bhargavkulk/89af241534b4509d214c80f0bc019d64 to your computer and use it in GitHub Desktop.
Scenario 1 answers lab 4
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
-- 1 | |
select ssid | |
from students | |
order by marks desc | |
limit 1 offset 1; | |
-- 2 | |
select branch, count(branch) | |
from students | |
group by branch | |
having count(branch) >= 3; | |
-- 3 | |
select branch, avg(marks) | |
from students | |
group by branch | |
having avg(marks) > ( | |
select avg(marks) | |
from students | |
where gender = 'FEMALE' | |
); | |
-- 4 | |
select branch, avg(marks) | |
from students | |
where gender = "MALE" | |
group by branch | |
having avg(marks) > ( | |
select avg(marks) | |
from students | |
where gender = 'FEMALE' | |
); | |
-- 5 | |
with males(branch, avg_marks) as ( | |
select branch, avg(marks) | |
from (select * from students where gender = 'MALE') m | |
group by branch | |
), | |
females (branch, avg_marks) as ( | |
select branch, avg(marks) | |
from (select * from students where gender = 'FEMALE') f | |
group by branch | |
) | |
select males.branch, males.avg_marks | |
from males, females | |
where males.branch = females.branch and males.avg_marks > females.avg_marks; | |
-- 6 | |
select max(m.marks) - max(f.marks) | |
from (select marks from students where gender = 'MALE') m, (select marks from students where gender = 'FEMALE') f; | |
-- 7 | |
select count(*) | |
from students | |
where 90 > marks and marks > 70 and branch = 'CS'; | |
-- 8 | |
update students | |
set gender = lower(gender) | |
where ssid <> ''; | |
select gender from students; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment