当前位置:网站首页>Sqlzoo question brushing record-2
Sqlzoo question brushing record-2
2022-06-09 07:28:00 【Amelia who loves learning】
- List per capita in each country in Europe GDP, Per capita GDP It is higher than that of Britain ’United Kingdom’ The value of .
select name from world
where GDP/population>
(select GDP/population from world
where name='United Kingdom') and continent='Europe';
- In Argentina Argentina And Australia Australia In the state of , List the names of the countries name And zhoufen continent . Sort by country name .
select name,continent from world
where continent in
(select continent from world
where name in ('Argentina','Australia'))
order by name;
- Which country has a larger population than Canada Canada More , But more than Poland Poland The less ? List country names name And population population .
select name,population from world
where population>(Select population from world
where name = 'Canada')
and
population<(select population from world
where name = 'Poland');
- Germany Germany ( Population 8000 Ten thousand ), stay Europe European countries have the largest population .Austria Austria ( Population 850 Ten thousand ) Of the total population of Germany 11%. Displays the European country name name And the population of each country population. Show the population as a percentage of the population of Germany .
select name,concat(ROUND(population/(
select population from world
where name='Germany')*100,0),'%') from world
where continent='europe';
- Which countries GDP Than Europe All the countries in Europe are tall ? [ Just list name .] ( In the records of some countries ,GDP yes NULL, No information is filled in .)
select name from world
where GDP>
(select max(GDP) from world
where continent = 'Europe');
- Find the largest country in each state , List the States continent, The name of the country name And area area. ( In the records of some countries ,AREA yes NULL, No information is filled in .)
SELECT continent, name, area FROM world x
WHERE area>= ALL
(SELECT area FROM world y
WHERE y.continent=x.continent
AND area>0)
- Find the continent , All of them are less than or equal to 25000000 Population . In these States , List country names name,continent Chaufen and population Population .
select name,continent,population from world x
where 25000000>=all(select population from world y
where y.continent=x.continent and population>0);
- The population of some countries is that of all other countries on the continent 3 Times or more . List The name of the country name and Zhoufen continent.
select name,continent from world x
where population/3>=all (select population from world y
where x.continent=y.continent and x.name<>y.name);
- The population of some countries is that of all other countries on the continent 3 Times or more . List The name of the country name and Zhoufen continent.
select name,continent from world x
where population/3>=all (select population from world y
where x.continent=y.continent
and x.name != y.name
and y.population>0);
- Show the total population of the world .
SELECT sum(population) FROM world;
- List all the States , Each one only once .
select distinct continent from world;
- Find Africa (Africa) Of GDP Sum .
select sum(GDP) from world
where continent = 'Africa';
- How many countries have at least a million (1000000) The area of .
select count(name) from world
where area>=1000000;
- (‘France’,‘Germany’,‘Spain’)(“ France ”,“ Germany ”,“ Spain ”) What is the total population of ?
select sum(population) from world
where name in ('France','Germany','Spain');
- For every continent , Show the number of States and countries .
select distinct continent,count(continent) from world
group by continent;
- For every continent , Show States and at least 1000 Ten thousand people (10,000,000) Number of exporting countries .
select continent,count(continent) from world
where population >= 10000000
group by continent;
- List at least 100 Million (1 Billion )(100,000,000) The state of the population .
select continent from world
group by continent
having sum(population)>100000000;
- The first example lists players whose last names are ’Bender’ The goal data of . * Indicates to list all fields of a table , It simplifies writing matchid, teamid, player, gtime Sentence . Modify the SQL To list Event number matchid And player names player , The player represents the German team Germany Goal scored . To find out the German players , To check : teamid = ‘GER’.
SELECT matchid,player FROM goal
WHERE teamid = 'GER';
- From the above query , You can see Lars Bender’s In the event 1012 Score a goal .. Now we want to know which team is playing in this event . Pay attention to goal Fields in the table matchid , Is the corresponding table game The field of id. We can use the form game Find out the events in 1012 Information about . Show only events 1012 Of id, stadium, team1, team2.
SELECT id,stadium,team1,team2 FROM game g
where g.id = 1012;
- We can use JOIN To do the above two steps at the same time .SELECT *
FROM game JOIN goal ON (id=matchid), Sentence FROM Means to join two tables game and goal Data for . Sentence ON Indicates how to find out game Each column in the should be paired goal Which column in – goal Of id Must pair game Of matchid . In short , Namely ON (game.id=goal.matchid) following SQL List each player who scores ( From goal form ) And venue name ( From game form ), Modify it to display the name of each German player who scores a goal , Team name , Venue and date .
SELECT player,teamid,stadium,mdate
FROM game JOIN goal ON (id=matchid)
where teamid = 'GER';
- List the names of the players Mario (player LIKE ‘Mario%’) There are goals Team 1 team1, Team 2 team2 and Player name player.
select team1,team2,player from goal
join game on (id=matchid)
where player like 'Mario%';
- form eteam Stored the data of each national team , Including the coach . You can use statements goal JOIN eteam on teamid=id Come together JOIN form goal To form eteam. List the first in each game 10 Minutes gtime<=10 There are players who score player, Team teamid, Coach coach, Goal time gtime.
SELECT player, teamid, coach, gtime
FROM goal join eteam on teamid = id
WHERE gtime<=10;
- We should put them together JOIN form game And forms eteam, You can use game JOIN eteam ON (team1=eteam.id) or game JOIN eteam ON (team2=eteam.id) Note the field id It's also a table game And forms eteam The field of , You should point out clearly eteam.id Not just id.
select mdate, teamname from game join eteam on (game.team1=eteam.id)
where eteam.coach = 'Fernando Santos';
- List venues 'National Stadium, Warsaw’ Our goal scorer .
select player from game join goal on matchid = id
where stadium = 'National Stadium, Warsaw';
- The following example finds Germany - Greece Germany-Greece The goal of the top eight competition of
Modify it , Just list all events , The name of the player who shot into the German goal .
select distinct player from game g1 join goal g2 on matchid = id
where (g1.team1='GER'and teamid !='GER')
or (g1.team2='GER'and teamid !='GER');
- List team names teamname And the total number of goals scored by the team
SELECT distinct teamname, count(player)
FROM eteam JOIN goal ON id=teamid
group BY teamname;
- List the name of the venue and the number of goals scored at the venue .
select distinct stadium,count(gtime) from game join goal on matchid=id
group by stadium;
- Every polish ’POL’ In the event of participation , List the event number matchid, date date And goal numbers .
SELECT matchid,mdate,count(team1)
FROM game JOIN goal ON matchid = id
WHERE (team1 = 'POL' OR team2 = 'POL')
group by matchid,mdate;
- Every German ’GER’ In the event of participation , List the event number matchid, date date And Germany's goal numbers .
select matchid,mdate,count(teamid) from game join goal on matchid=id
where (team1 = 'GER' or team2 = 'GER') and teamid = 'GER'
group by matchid,mdate;
- List every match with the goals scored by each team as shown. This will use “CASE WHEN” which has not been explained in any previous exercises.Notice in the query given every goal is listed. If it was a team1 goal then a 1 appears in score1, otherwise there is a 0. You could SUM this column to get a count of the goals scored by team1. Sort your result by mdate, matchid, team1 and team2.
select mdate,
team1, SUM(CASE WHEN teamid = team1 THEN 1 ELSE 0 END) AS score1,
team2, SUM(CASE WHEN teamid = team2 THEN 1 ELSE 0 END) AS score2
FROM game LEFT OUTER JOIN goal
on game.id = goal.matchid
GROUP BY mdate, id, team1, team2;
边栏推荐
- 软件设计文档最容易忽略哪些?
- Summarize 2021 Test Engineer Interview Questions (including answers)
- 2022年7月2日下午,济南IT技术聚会,感兴趣的朋友扫码报名并入群交流
- Large factory interview algorithm series - dynamic programming for solving the longest common substring problem
- C语言文件——字符串的方式读出与写入
- The sandbox and ikonia have reached a cooperation to restore the murals of the football legend Pirlo in the metauniverse
- Pycharm and MySQL as a student information management system
- Opengauss database operation steps
- 多余的时间不要浪费,玩玩手机可开启“副业人生”
- Squid proxy application
猜你喜欢

Jasperreport generate PDF report section

使用OpenCore引导黑苹果

Technology sharing | discussion on the design of dispatching platform

UML总结

PostgreSQL database semaphore mechanism pgsemaphore underlying principle

朴素贝叶斯分类器

知行之桥EDI系统Shopify端口的使用

Common classes - overview of string classes

Opengauss database operation steps

error converting YAML to JSON: yaml: line 10: found character that cannot start any token
随机推荐
Question bank and answers of 2022 special operation certificate for installation and repair of refrigeration and air conditioning equipment
Two ways to achieve single sign on
2022 national latest Fire Facility operator (Intermediate Fire Facility operator) test Simulated question base and Answers
线程的调度、线程的优先级
PostgreSQL数据库复制——后台一等公民进程WalReceiver 提取信息
2022年塔式起重机司机(建筑特殊工种)考试题模拟考试题库及模拟考试
「冲刺大厂基础1」
5. Multimedia Foundation
2022加氢工艺题库及模拟考试
Technology sharing | discussion on the design of dispatching platform
It is so simple to realize the rotation chart!!!
Cognition of clothing and textile industry
C语言fopen函数的编程实现(可直接粘贴走验证)
How idea views the path to save code
How about opening an account for shares of tongdaxin? Is it safe to open an account?
Code of conduct for industrial control safety
Boot Black apple with OpenCORE
2022年全國最新消防設施操作員(中級消防設施操作員)考試模擬題庫及答案
浅谈数据库优化(以mysql为例)
100 code structure and how to avoid them (4)