sql练习-基础练习
闲来无事,找个网站练习sql基础。
练习网站:
https://zh.sqlzoo.net/wiki/SQL_Tutorial
练习区域,左边导航栏
SELECT within SELECT Tutorial/zh
2.列出欧洲每国家的人均GDP,当中人均GDP要高于英国’United Kingdom’的数值。
select namefrom worldwhere continent = 'Europe'and (gdp / population) >(select gdp / population from world where name = 'United Kingdom');
3.在阿根廷Argentina 及 澳大利亚 Australia所在的洲份中,列出当中的国家名字 name 及洲分 continent 。按国字名字顺序排序。
select name, continentfrom worldwhere continent in (select continentfrom worldwhere name = 'Argentina 'or name = 'Australia')order by name
4.哪一个国家的人口比加拿大Canada的多,但比波兰Poland的少?列出国家名字name和人口population 。
select name, populationfrom worldwhere population > (select population from world where name = 'Canada')and population < (select population from world where name = 'Poland')
5.Germany德国(人口8000万),在Europe欧洲国家的人口最多。Austria奥地利(人口850万)拥有德国总人口的11%。
显示欧洲的国家名称name和每个国家的人口population。以德国的人口的百分比作人口显示。
select name,concat(round(population /(select population from world where name = 'Germany') * 100),'%')from worldwhere continent = 'Europe'
6.哪些国家的GDP比Europe欧洲的全部国家都要高呢? [只需列出 name 。] (有些国家的记录中,GDP是NULL,沒有填入资料的。)
select namefrom worldwhere gdp > all (select gdpfrom worldwhere gdp > 0and continent = 'Europe')
7.在每一个州中找出最大面积的国家,列出洲份 continent, 国家名字 name 及面积 area。 (有些国家的记录中,AREA是NULL,沒有填入资料的。)
select continent, name, areafrom world xwhere area >= all (select areafrom world ywhere y.continent = x.continentand area > 0)
8.列出洲份名称,和每个洲份中国家名字按子母顺序是排首位的国家名。(即每洲只有列一国)
select continent, namefrom (select continent,name,row_number() over(partition by continent order by name) as numfrom world) awhere a.num = '1';
9.找出洲份,当中全部国家都有少于或等于 25000000 人口. 在这些洲份中,列出国家名字name,continent 洲份和population人口。
select name, continent, populationfrom world awhere (select max(population) from world b where a.continent = b.continent) <= 25000000
10.有些国家的人口是同洲份的所有其他国的3倍或以上。列出 国家名字name 和 洲份 continent。
select name, continentfrom world awhere (select a.population / 3 >= all (select populationfrom world bwhere a.continent = b.continentand a.name != b.name))
2020/4/28更新
练习区域,左边导航栏
join
1.要找出德国队球员
SELECT matchid,player FROM goal WHERE teamid = 'GER'
2.只显示赛事1012的 id, stadium, team1, team2
SELECT id,stadium,team1,team2FROM game where id = '1012'
3.显示每一个德国入球的球员名,队伍名,场馆和日期。
SELECT player, teamid, stadium, mdateFROM gameJOIN goalON (id = matchid)and teamid = 'GER'
4.列出球员名字叫Mario (player LIKE ‘Mario%’)有入球的 队伍1 team1, 队伍2 team2 和 球员名 player
select team1, team2, playerfrom gamejoin goalon player like 'Mario%'and id = matchid
5.列出每场球赛中首10分种gtime<=10有入球的球员 player, 队伍teamid, 教练coach, 入球时间gtime
SELECT player, teamid, coach, gtimeFROM goaljoin eteamon teamid = idWHERE gtime <= 10
6.列出’Fernando Santos’作为队伍1 team1 的教练的赛事日期,和队伍名。
select mdate, teamnamefrom eteamjoin gameon (team1 = eteam.id)and coach = 'Fernando Santos'
7.列出场馆 'National Stadium, Warsaw’的入球球员。
select playerfrom goaljoin gameon matchid = idand stadium = 'National Stadium, Warsaw'
8.列出全部赛事,射入德国龍門的球员名字。
SELECT distinct (player)FROM gameJOIN goalON matchid = idand ((team1 = 'GER' and team2 = teamid) or(team1 = teamid and team2 = 'GER'))
9.列出队伍名称 teamname 和该队入球总数.
select teamname, count(teamname)from eteamjoin goalon id = teamidgroup by teamnameorder by teamname
10.列出场馆名和在该场馆的入球数字。
select stadium, count(*)from gamejoin goalon id = matchidgroup by stadiumorder by stadium
11.每一场波兰’POL’有参与的赛事中,列出赛事编号 matchid, 日期date 和入球数字.
select matchid, mdate, count(*)from gamejoin goalon matchid = idwhere (team1 = 'POL' or team2 = 'POL')group by matchid, mdate
12.每一场德国’GER’有参与的赛事中,列出赛事编号 matchid, 日期date 和德国的入球数字。
select matchid, mdate, count(*)from gamejoin (select matchid, teamid from goal where teamid = 'GER') aon a.matchid = idgroup by matchid, mdate
13.列出所有比赛的每个队的比分
select
b.mdate,
b.team1,sum(case when teamid=team1 then 1 else 0 end) as score1,
b.team2,sum(case when teamid=team2 then 1 else 0 end) as score2
from
(select id ,mdate, team1, team2 from game) b
left join
(select matchid, teamid from goal) a
on a.matchid = b.id
group by b.mdate, b.team1, b.team2
order by b.mdate, b.team1, b.team2;
2020/5/13更新
练习区域,左边导航栏
more join
1.列出電影北非諜影 'Casablanca’的演員名單。
select a.namefrom actor a, casting c, movie mwhere a.id = c.actoridand c.movieid = m.idand m.title = 'Casablanca'
2.顯示電影異型’Alien’ 的演員清單。
select a.namefrom actor a, casting c, movie mwhere a.id = c.actoridand c.movieid = m.idand m.title = 'Alien'
3.列出演員夏里遜福 ‘Harrison Ford’ 曾演出的電影。
select m.titlefrom actor a, casting c, movie mwhere a.id = c.actoridand c.movieid = m.idand a.name = 'Harrison Ford'
4.列出演員夏里遜福 ‘Harrison Ford’ 曾演出的電影,但他不是第1主角。
sql练习-基础练习相关推荐
- 实验四 数据库SQL语言基础编程
-- 实验四 数据库SQL语言基础编程 -- 实验目的: -- 掌握数据库查询语句的编写方法 -- 掌握利用查询语言完成基本查询 -- 掌握利用SQL语句完成数据的添加.删除.修改操作 -- 实 ...
- PL/SQL语言基础
PL/SQL语言基础 /********************************数据类型*************************************/ %rowtype (行对 ...
- SQL Tuning 基础概述10
在<SQL Tuning 基础概述05 - Oracle 索引类型及介绍>的1.5小节,提到了几种"索引的常见执行计划": INDEX FULL SCAN:索引的全扫描 ...
- 整理一些sql server基础资料
闲来无事,整理些sql server 基础资料,以便以后查找.复习 SQL Server日期计算 a. 一个月的第一天 Select DATEADD(mm, DATEDIFF(mm,0,getdate ...
- SQL Server基础知识概念要点详细讲解
SQL Server基础知识概念要点详细讲解 目录 基础概念 1.网状模型数据库 2.层次模型数据库 3.关系模型数据库 知识点实例总结 基础概念 SQL语言中,between and表示包括两边参数 ...
- 一文搞懂 SQL:基础知识和业务实践总结
作者:cooperyjli,腾讯 CDG 数据分析师 SQL的全称是Structured Query Language(结构化查询语言),是一种古老而简洁的程序设计语言.看似平平无奇,一直被各种吐槽, ...
- mysql分析sql语句基础工具 —— explain
转载自 https://segmentfault.com/a/1190000009724144 立即登录 [笔记] mysql分析sql语句基础工具 -- explain mysql wateran ...
- 10、oracle下PL/SQL编程基础
ORACLE下的PL/SQL编程基础 PL/SQL语言是程序化程序设计语言,块是PL/SQL编程中的基本结构,其优点在于支持SQL.支持面向对象编程.性能好.可移植性.与sql集成.安全性高等. 1. ...
- sql number转varchar_MySQL 指南之 SQL 语句基础
个人所有文章整理在此篇,将陆续更新收录:知无涯,行者之路莫言终(我的编程之路) 零.结构化查询语言:SQL(Structured Query Language) DDL 数据定义语言 管理库,表 DM ...
- SQL零基础学习笔记(一)
真的不知道我写了这么多不同的的学习笔记又没用..开始SQL零基础学习笔记 百度百科:SQL(Structured Query Language)结构化查询语言,是一种数据库查询和程序设计语言,用于存取 ...
最新文章
- 简单快速修改大量重复代码(Intellij IDEA)
- matlab 数据保存为txt excel mat
- python excel操作xlrd_python操作Excel读写--使用xlrd
- 我将 20 年前开发的操作系统迁移到 .NET 6,竟然成功了!
- 小程序添加和删除新元素功能实例
- 同步的概念(python 版)
- document.execCommand() 命令详解 只支持IE
- pb数据窗口显示图片_AkShare股票数据A股市净率
- 网页加载速度优化方案
- 调剂2002年计算机科学与技术,东莞理工学院2020年硕士研究生调剂信息公告 (计算机科学与技术、资源与环境专业(原...
- java访问网络接口_Java网络访问 java调用http java调用其他接口
- linux 网桥配置命令:brctl
- scholarscope不显示影响因子_你的pubmed又不能显示影响因子了,因为 ……
- 【Python-神经网络】
- Docker 18.09.0更换阿里镜像加速器
- 插上U盘显示这个错误ERROR
- 云服务器是widows7系统,云服务器win7系统
- 2021-02-05仅供自己参考:多态使用
- java中的圈复杂度计算_[代码质量] 圈复杂度和代码质量优化(附带示例代码纠正代码质量)...
- 蚂蚁金服胡喜:自主研发不是用来捏在手里,是用来开放的