sqlzoo答案4:SELECT within SELECT Tutorial
sql练习:SELECT within SELECT Tutorial - SQLZoo
world表:
| name | continent | area | population | gdp |
|---|---|---|---|---|
| Afghanistan | Asia | 652230 | 25500100 | 20343000000 |
| Albania | Europe | 28748 | 2831741 | 12960000000 |
| Algeria | Africa | 2381741 | 37100000 | 188681000000 |
| Andorra | Europe | 468 | 78115 | 3712000000 |
| Angola | Africa | 1246700 | 20609294 | 100990000000 |
| ... | ||||
world(name, continent, area, population, gdp)
1. select...where...(...select...)
List each country name where the population is larger than that of 'Russia'.
SELECT name FROM worldWHERE population >(SELECT population FROM worldWHERE name='Russia')
2.
Show the countries in Europe with a per capita GDP greater than 'United Kingdom'.
Per Capita GDP?
The per capita GDP is the gdp/population
Europe是在continent里面筛选,不是area
select name
from world
where continent = 'Europe'
and gdp/population >
(select gdp/population
from world
where name= 'United Kingdom')
3. in 、order by
List the name and continent of countries in the continents containing either Argentina or Australia. Order by name of the country.
列出包含阿根廷或澳大利亚的大陆中的国家名称和所属大陆。按国家名称排序。
错误代码:理解错误,Argentina or Australia是国家名
select name, continent
from world
where continent in ('Argentina' , 'Australia')
order by name
正确代码:
select name, continent
from world
where continent in (
select continent
from world
where name in ('Argentina' , 'Australia'))
order by name
4.
Which country has a population that is more than United Kingdom but less than Germany? Show the name and the population.
select name, population
from world
where population >
(
select population from world
where name = 'United Kingdom')
and
population <
(
select population from world
where name = 'Germany')
5. concat...as、round
Germany (population 80 million) has the largest population of the countries in Europe. Austria (population 8.5 million) has 11% of the population of Germany.
Show the name and the population of each country in Europe. Show the population as a percentage of the population of Germany.
显示每个欧洲国家的名称和人口。以德国人口的百分比显示人口。
The format should be Name, Percentage for example:
| name | percentage |
|---|---|
| Albania | 3% |
| Andorra | 0% |
| Austria | 11% |
| ... | ... |
Decimal places?
You can use the function ROUND to remove the decimal places.
Percent symbol %
You can use the function CONCAT to add the percentage symbol.
select name, concat(round(population/
(
select population from world
where name = 'Germany'
)*100,0),'%') as percentage
from world
where continent = 'Europe'
To get a well rounded view of the important features of SQL you should move on to the next tutorial concerning aggregates.
To gain an absurdly detailed view of one insignificant feature of the language, read on.
We can use the word ALL to allow >= or > or < or <=to act over a list. For example, you can find the largest country in the world, by population with this query:
我们可以使用单词 ALL 来允许 >= 或 > 或 < 或 <= 在列表上操作。例如,你可以通过这个查询找到世界上人口最多的国家:
SELECT nameFROM worldWHERE population >= ALL(SELECT populationFROM worldWHERE population>0)
You need the condition population>0 in the sub-query as some countries have null for population.
6. all
Which countries have a GDP greater than every country in Europe? [Give the name only.] (Some countries may have NULL gdp values)
哪些国家的GDP高于欧洲所有国家?【仅提供名称】(某些国家可能没有GDP数值)
select name
from world
where gdp >
all(
select gdp from world
where continent = 'Europe' and gdp > 0 )
| name |
|---|
| China |
| Japan |
| United States |
7.对比同一个洲内 找最大area
Find the largest country (by area) in each continent, show the continent, the name and the area:
The above example is known as a correlated or synchronized sub-query.
找出每个洲面积最大的国家,显示洲名、国家名称和面积: 上述示例被称为相关或同步子查询。
Using correlated subqueries?
A correlated subquery works like a nested loop: the subquery only has access to rows related to a single record at a time in the outer query. The technique relies on table aliases to identify two different uses of the same table, one in the outer query and the other in the subquery.
One way to interpret the line in the WHERE clause that references the two table is “… where the correlated values are the same”.
In the example provided, you would say “select the country details from world where the population is greater than or equal to the population of all countries where the continent is the same”.
使用相关子查询?
相关子查询的工作方式类似于嵌套循环:子查询仅能访问外部查询中当前记录相关的行。这种技术依赖表别名来标识同一张表的两种不同用途,一个在外部查询中,另一个在子查询中。 可以将 WHERE 子句中引用两个表的那一行解释为“…其中相关值相同”。 在提供的示例中,你会说“从 world 表中选择国家详情,其中人口大于或等于所有同一大陆的国家的人口”。
SELECT continent, name, area FROM world xWHERE area>= ALL(SELECT area FROM world yWHERE y.continent=x.continentAND population>0)
8.min(name) 按字母顺序排列第一个
List each continent and the name of the country that comes first alphabetically.
列出每个大洲及按字母顺序排列第一个国家的名称。
select continent, name from world x
where name=(select min(name) from world ywhere x.continent = y.continent)
9.
Find the continents where all countries have a population <= 25000000. Then find the names of the countries associated with these continents. Show name, continent and population.
查找所有国家人口均不超过25000000的洲。然后找出与这些洲相关的国家名称。显示名称、洲和人口。
select name,continent, population
from world a
where 25000000 > all(select population from world bwhere a.continent = b.continent)
10.
Some countries have populations more than three times that of all of their neighbours (in the same continent). Give the countries and continents.
一些国家的人口是其邻国(在同一洲)人口总和的三倍以上。请给出这些国家及其所在的洲。
就是比同一洲上除了自己以外的其他国家人口都多三倍
select name, continent
from world a
where (population)/3>all(select population from world bwhere a.continent = b.continentand a.name<> b.name)相关文章:
sqlzoo答案4:SELECT within SELECT Tutorial
sql练习:SELECT within SELECT Tutorial - SQLZoo world表: namecontinentareapopulationgdpAfghanistanAsia6522302550010020343000000AlbaniaEurope28748283174112960000000AlgeriaAfrica238174137100000188681000000AndorraEurope46878115371200000…...
【fly-iot飞凡物联】(20):2025年总体规划,把物联网整套技术方案和实现并落地,完成项目开发和课程录制。
前言 fly-iot飞凡物联专栏: https://blog.csdn.net/freewebsys/category_12219758.html 1,开源项目地址进行项目开发 https://gitee.com/fly-iot/fly-iot-platform 完成项目开发,接口开发。 把相关内容总结成文档,并录制课程。…...
Lucene常用的字段类型lucene检索打分原理
在 Apache Lucene 中,Field 类是文档中存储数据的基础。不同类型的 Field 用于存储不同类型的数据(如文本、数字、二进制数据等)。以下是一些常用的 Field 类型及其底层存储结构: TextField: 用途:用于存储…...
适用于IntelliJ IDEA 2024.1.2部署Tomcat的完整方法,以及笔者踩的坑,避免高血压,保姆级教程
Tips:创建部署Tomcat直接跳转到四 一、软件准备 笔者用的是IntelliJ IDEA 2024.1.2和Tomcat 8.5。之前我使用的是Tomcat 10,但遇到了许多问题。其中一个主要问题是需要使用高于1.8版本的JDK,为此我下载了新的JDK版本,但这又引发了更多的兼容…...
XSS靶场通关详解
前言 这里作者采用phpstudy部署的xss-lab靶场,配置如下: 第一关 进入靶场后寻找页面的传参处,发现url中的name参数传了test给页面,可以在此处进行尝试xss 成功弹窗! payload: <script>alert(1)<…...
Excel 技巧15 - 在Excel中抠图头像,换背景色(★★)
本文讲了如何在Excel中抠图头像,换背景色。 1,如何在Excel中抠图头像,换背景色 大家都知道在PS中可以很容易抠图头像,换背景色,其实Excel中也可以抠简单的图,换背景色。 ※所用头像图片为百度搜索&#x…...
备忘-humanplus相关的代码解析
-1: numpy必须为1.20.0,否则会报错,版本冲突0.rlvalue-based: 如q-learning(走迷宫),对当前状态下作出的动作进行价值计算,通过贪婪策略穷尽所有可能选择最佳state-action,但是对于连续的动作空间&#x…...
青少年编程与数学 02-008 Pyhon语言编程基础 01课题、语言概要
青少年编程与数学 02-008 Pyhon语言编程基础 01课题、语言概要 一、榜一大哥起源与早期发展版本演进与社区壮大应用领域的拓展编程语言排行榜的常客结语 二、当前排行三、出色表现四、易学易用五、特色显著六、资源丰富初学者资源中高级学习资源在线编程学习平台 课题摘要:本文…...
XSS (XSS)分类
XSS (XSS) 概要 XSS全称为Cross Site Scripting,为了和CSS分开简写为XSS,中文名为跨站脚本。该漏洞发生在用户端,是指在渲染过程中发生了不在预期过程中的JavaScript代码执行。XSS通常被用于获取Cookie、以受攻击者的…...
[Linux]el8安全配置faillock:登录失败达阈值自动锁定账户配置
前言 本篇文章的配置仅使用于el8版本的Linux,目前已在centos8、BCLinux8上验证成功,其他版本系统是否可行还得考查。 el8中管理用户登录失败锁定账户所用的模块是faillock.so,如果想要将配置应用与其他版本的Linux,建议确认Linux…...
最新-CentOS 7安装1 Panel Linux 服务器运维管理面板
CentOS 7安装1 Panel Linux 服务器运维管理面板 一、前言二、环境要求三、在线安装四、离线安装1.点击下面1 Panel官网链接访问下载,如未登录或注册,请登录/注册后下载2.使用将离线安装包上传至目标终端/tem目录下3.进入到/tem目录下解压离线安装包4.执行…...
selenium定位网页元素
1、概述 在使用 Selenium 进行自动化测试时,定位网页元素是核心功能之一。Selenium 提供了多种定位方法,每种方法都有其适用场景和特点。以下是通过 id、linkText、partialLinkText、name、tagName、xpath、className 和 cssSelector 定位元素的…...
積分方程與簡單的泛函分析8.具連續對稱核的非齊次第II類弗雷德霍姆積分算子方程
1)def求解具連續對稱核的非齊次第II類弗雷德霍姆積分算子方程 设 是定义在上的连续对称核函数, 非齐次第二类弗雷德霍姆积分算子方程的形式为: , 其中是未知函数,是给定的连续函数,是参数。 2)def其特徵值是否一致…...
长理算法复习
选择排序 #include<iostream>using namespace std;const int N 1010; int a[N]; int n;void selectSort(){for (int i 0; i < n;i){int pos i;for (int j i 1; j < n;j){if(a[j]<a[pos])pos j;}swap(a[i], a[pos]);} }int main() {cin >> n;for (i…...
机器学习-K近邻算法
文章目录 一. 数据集介绍Iris plants dataset 二. 代码三. k值的选择 一. 数据集介绍 鸢尾花数据集 鸢尾花Iris Dataset数据集是机器学习领域经典数据集,鸢尾花数据集包含了150条鸢尾花信息,每50条取自三个鸢尾花中之一:Versicolour、Setosa…...
使用rsync+inotify简单实现文件实时双机双向同步
使用rsyncinotify简单实现文件实时双机双向同步 实现思路 使用inotify-tools的inotifywait工具监控文件变化,触发后使用rsync做同步。加入系统服务项,实现实时监听,方便管理。 以下配置操作,单向同步,只需在单边部…...
Ubuntu 24.04 LTS开机自启动脚本设置方法
目录 Ubuntu中设置开机自启动脚本步骤1:修改 rc-local.service文件步骤2:创建/etc/rc.local文件步骤3:修改/etc/rc.local的权限步骤4:启动rc-local.service步骤5:查看rc-local.service的服务状态 Ubuntu中设置开机自启…...
谈谈对JavaScript 中的事件冒泡(Event Bubbling)和事件捕获(Event Capturing)的理解
JavaScript 中的事件冒泡(Event Bubbling)和事件捕获(Event Capturing),是浏览器在处理事件时采用的两种机制,它们在事件的传播顺序上有显著区别。这两种机制帮助开发者在事件触发时,能够以不同…...
解读2025年生物医药创新技术:展览会与论坛的重要性
2025生物医药创新技术与应用发展展览会暨论坛,由天津市生物医药行业协会、BIO CHINA生物发酵展组委会携手主办,山东信世会展服务有限公司承办,定于2025年3月3日至5日在济南黄河国际会展中心盛大开幕。展会规模60000平方米、800参展商、35场会…...
【第七天】零基础入门刷题Python-算法篇-数据结构与算法的介绍-一种常见的分治算法(持续更新)
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言一、Python数据结构与算法的详细介绍1.Python中的常用的分治算法2. 分治算法3.详细的分治代码1)一种常见的分治算法 总结 前言 提示:这…...
web vue 项目 Docker化部署
Web 项目 Docker 化部署详细教程 目录 Web 项目 Docker 化部署概述Dockerfile 详解 构建阶段生产阶段 构建和运行 Docker 镜像 1. Web 项目 Docker 化部署概述 Docker 化部署的主要步骤分为以下几个阶段: 构建阶段(Build Stage):…...
云原生核心技术 (7/12): K8s 核心概念白话解读(上):Pod 和 Deployment 究竟是什么?
大家好,欢迎来到《云原生核心技术》系列的第七篇! 在上一篇,我们成功地使用 Minikube 或 kind 在自己的电脑上搭建起了一个迷你但功能完备的 Kubernetes 集群。现在,我们就像一个拥有了一块崭新数字土地的农场主,是时…...
论文解读:交大港大上海AI Lab开源论文 | 宇树机器人多姿态起立控制强化学习框架(二)
HoST框架核心实现方法详解 - 论文深度解读(第二部分) 《Learning Humanoid Standing-up Control across Diverse Postures》 系列文章: 论文深度解读 + 算法与代码分析(二) 作者机构: 上海AI Lab, 上海交通大学, 香港大学, 浙江大学, 香港中文大学 论文主题: 人形机器人…...
STM32标准库-DMA直接存储器存取
文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA(Direct Memory Access)直接存储器存取 DMA可以提供外设…...
P3 QT项目----记事本(3.8)
3.8 记事本项目总结 项目源码 1.main.cpp #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) {QApplication a(argc, argv);Widget w;w.show();return a.exec(); } 2.widget.cpp #include "widget.h" #include &q…...
Android 之 kotlin 语言学习笔记三(Kotlin-Java 互操作)
参考官方文档:https://developer.android.google.cn/kotlin/interop?hlzh-cn 一、Java(供 Kotlin 使用) 1、不得使用硬关键字 不要使用 Kotlin 的任何硬关键字作为方法的名称 或字段。允许使用 Kotlin 的软关键字、修饰符关键字和特殊标识…...
重启Eureka集群中的节点,对已经注册的服务有什么影响
先看答案,如果正确地操作,重启Eureka集群中的节点,对已经注册的服务影响非常小,甚至可以做到无感知。 但如果操作不当,可能会引发短暂的服务发现问题。 下面我们从Eureka的核心工作原理来详细分析这个问题。 Eureka的…...
【生成模型】视频生成论文调研
工作清单 上游应用方向:控制、速度、时长、高动态、多主体驱动 类型工作基础模型WAN / WAN-VACE / HunyuanVideo控制条件轨迹控制ATI~镜头控制ReCamMaster~多主体驱动Phantom~音频驱动Let Them Talk: Audio-Driven Multi-Person Conversational Video Generation速…...
Python基于历史模拟方法实现投资组合风险管理的VaR与ES模型项目实战
说明:这是一个机器学习实战项目(附带数据代码文档),如需数据代码文档可以直接到文章最后关注获取。 1.项目背景 在金融市场日益复杂和波动加剧的背景下,风险管理成为金融机构和个人投资者关注的核心议题之一。VaR&…...
uniapp 小程序 学习(一)
利用Hbuilder 创建项目 运行到内置浏览器看效果 下载微信小程序 安装到Hbuilder 下载地址 :开发者工具默认安装 设置服务端口号 在Hbuilder中设置微信小程序 配置 找到运行设置,将微信开发者工具放入到Hbuilder中, 打开后出现 如下 bug 解…...
