URI Online Judge Solution 2740 League Using PostgreSQL Query Language.The International Underground Excavation League is a success between alternative sports, however the staff responsible for organizing the events doesn’t understand computers at all, they only know how to dig and the sport rule set. As such, you were hired to solve the League’s problem.
Select the three first placed with the initial phrase "Podium: " and select the last two, which will be demoted to a lower league with the initial phrase “Demoted:".
Schema
leagueColumn | Type |
position (PK) | integer |
team | varchar |
Tables
leagueposition | team |
1 | The Quack Bats |
2 | The Responsible Hornets |
3 | The Bawdy Dolphins |
4 | The Abstracted Sharks |
5 | The Nervous Zebras |
6 | The Oafish Owls |
7 | The Unequaled Bison |
8 | The Keen Kangaroos |
9 | The Left Nightingales |
10 | The Terrific Elks |
11 | The Lumpy Frogs |
12 | The Swift Buffalo |
13 | The Big Chargers |
14 | The Rough Robins |
15 | The Silver Crocs |
Output Sample
name |
Podium: The Quack Bats |
Podium: The Responsible Hornets |
Podium: The Bawdy Dolphins |
Demoted: The Rough Robins |
Demoted: The Silver Crocs |
URI 2740 Solution in PostgreSQL:
SELECT Concat('Podium: ', team) as name
FROM League
WHERE position IN (SELECT MIN(position) FROM League)
UNION ALL
SELECT Concat('Podium: ', team)
FROM League
WHERE position IN (SELECT MIN(position)+1 FROM League)
UNION ALL
SELECT Concat('Podium: ', team)
FROM League
WHERE position IN (SELECT MIN(position)+2 FROM League)
UNION ALL
SELECT Concat('Demoted: ', team)
FROM League
WHERE position IN (SELECT MAX(position)-1 FROM League)
UNION ALL
SELECT Concat('Demoted: ', team)
FROM League
WHERE position IN (SELECT MAX(position) FROM League)
(select concat('Podium: ',team) as name from league
ReplyDeletewhere position in (select position from league order by position limit 3))
union all
(select concat('Demoted: ',team) as name from league
where position in (select position from league order by position desc limit 2))