SQL을 공부해보자!
world(name, continent, area, population, gdp)
ANSWER :
SELECT name FROM world
WHERE population >
(SELECT population FROM world
WHERE name='Russia')
ANSWER :
SELECT name FROM world
WHERE continent='Europe' AND gdp/population >
(SELECT gdp/population FROM world
WHERE name='United Kingdom')
ANSWER :
SELECT name, continent FROM world
WHERE continent IN (
SELECT continent FROM world
WHERE name='Argentina' OR name='Australia'
)
ORDER BY name ASC;
ANSWER :
SELECT name, population FROM world
WHERE population > (
SELECT population FROM world
WHERE name='Canada'
) AND population< (
SELECT population FROM world
WHERE name='Poland'
)
Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.
ANSWER :
SELECT name, CONCAT(ROUND(population/(SELECT population FROM world WHERE name='Germany')*100, 0),'%')
FROM world
WHERE continent='Europe'
ANSWER :
SELECT name
FROM world
WHERE gdp > ALL(SELECT gdp
FROM world
WHERE continent='Europe'
AND gdp IS NOT NULL);
ANSWER :
SELECT continent, name, area
FROM world x
WHERE area >= ALL(SELECT area FROM world y WHERE x.continent=y.continent)
ANSWER :
SELECT continent, name
FROM world x
WHERE name <= ALL(SELECT name FROM world y WHERE x.continent=y.continent)
ANSWER :
SELECT name, continent, population
FROM world x
WHERE 25000000 >= ALL(SELECT population FROM world y WHERE x.continent=y.continent)
ANSWER :
SELECT name, continent
FROM world x
WHERE x.population > ALL(SELECT population*3 FROM world y WHERE x.continent=y.continent AND x.name != y.name)
Modify it to show the matchid and player name for all goals scored by Germany. To identify German players, check for: teamid = 'GER'
Answer :
SELECT matchid, player
FROM goal
WHERE teamid LIKE '%GER'
Notice in the that the column matchid in the goal table corresponds to the id column in the game table. We can look up information about game 1012 by finding that row in the game table.
Show id, stadium, team1, team2 for just game 1012
Answer :
SELECT id,stadium,team1,team2
FROM game
WHERE id LIKE '%1012%'
SELECT *
FROM game JOIN goal ON (id=matchid)
The FROM clause says to merge data from the goal table with that from the game table. The ON says how to figure out which rows in game go with which rows in goal - the matchid from goal must match id from game. (If we wanted to be more clear/specific we could say
ON (game.id=goal.matchid)
The code below shows the player (from the goal) and stadium name (from the game table) for every goal scored.
Modify it to show the player, teamid, stadium and mdate for every German goal.
Answer :
SELECT player, teamid, stadium, mdate
FROM game
JOIN goal ON (id=matchid)
WHERE teamid LIKE '%Ger%'
Show the team1, team2 and player for every goal scored by a player called Mario player LIKE 'Mario%'
Answer :
SELECT team1, team2, player
FROM game
JOIN goal ON (id=matchid)
WHERE player LIKE 'Mario%'
5. The table eteam gives details of every national team including the coach. You can JOIN goal to eteam using the phrase goal JOIN eteam on teamid=id
Show player, teamid, coach, gtime for all goals scored in the first 10 minutes gtime<=10
SELECT player, teamid, coach, gtime
FROM goal
JOIN eteam ON (teamid=id)
WHERE gtime<=10
6. To JOIN game with eteam you could use either
game JOIN eteam ON (team1=eteam.id) or game JOIN eteam ON (team2=eteam.id)
Notice that because id is a column name in both game and eteam you must specify eteam.id instead of just id
List the dates of the matches and the name of the team in which 'Fernando Santos' was the team1 coach.
SELECT mdate, teamname
FROM game
JOIN eteam ON (game.team1=eteam.id)
WHERE coach LIKE 'Fernando Santos'
7. List the player for every goal scored in a game where the stadium was 'National Stadium, Warsaw'
SELECT player
FROM goal
JOIN game ON (matchid = id)
WHERE stadium LIKE 'National Stadium, Warsaw'
8. The example query shows all goals scored in the Germany-Greece quarterfinal.
Instead show the name of all players who scored a goal against Germany.
SELECT DISTINCT(player)
FROM goal
JOIN game ON (matchid = id)
WHERE (team1 LIKE 'GER' OR team2 LIKE 'GER') AND NOT teamid LIKE 'GER'
9. Show teamname and the total number of goals scored.
SELECT teamname, COUNT(teamname)
FROM goal
JOIN eteam ON (teamid=id)
GROUP BY teamname
10. Show the stadium and the number of goals scored in each stadium.
SELECT stadium, COUNT(stadium)
FROM game
JOIN goal ON (id=matchid)
GROUP BY stadium
11. For every match involving 'POL', show the matchid, date and the number of goals scored.
SELECT matchid, mdate, COUNT(matchid)
FROM game
JOIN goal ON (id=matchid)
WHERE team1 LIKE 'POL' OR team2 LIKE 'POL'
GROUP BY matchid, mdate
12. For every match where 'GER' scored, show matchid, match date and the number of goals scored by 'GER'
SELECT matchid, mdate, COUNT(matchid)
FROM game
JOIN goal ON (id=matchid)
WHERE teamid LIKE 'GER'
GROUP BY matchid, mdate
Sophia had always been fascinated by the fantasy genre, so when she discovered an online slot game with a magical theme, she was immediately intrigued. The game promised an immersive experience with enchanting graphics https://micasino-cl.cl/ and a captivating storyline that drew her into a fantastical world. Sophia decided to dive in, starting with small bets as she familiarized herself with the game’s features and bonus rounds. The slot’s whimsical animations and magical symbols created an engaging and entertaining atmosphere.