SQL ZOO 练习 —— SELECT names

2023-11-21 03:10

本文主要是介绍SQL ZOO 练习 —— SELECT names,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

在这里插入图片描述

1.You can use WHERE name LIKE ‘B%’ to find the countries that start with “B”.

The % is a wild-card it can match any characters
Find the country that start with Y

SELECT name FROM worldWHERE name LIKE 'Y%'

2.Find the countries that end with y

SELECT name FROM worldWHERE name LIKE '%Y'

3.Luxembourg has an x - so does one other country. List them both.

Find the countries that contain the letter x

SELECT name FROM worldWHERE name LIKE '%x%'

4.Iceland, Switzerland end with land - but are there others?

Find the countries that end with land

SELECT name FROM worldWHERE name LIKE '%land'

5.Columbia starts with a C and ends with ia - there are two more like this.

Find the countries that start with C and end with ia

SELECT name FROM worldWHERE name LIKE 'C%'AND name LIKE '%ia'

6.Greece has a double e - who has a double o?

Find the country that has oo in the name

SELECT name FROM worldWHERE name LIKE '%oo%'

7.Bahamas has three a - who else?

Find the countries that have three or more a in the name

SELECT name FROM worldWHERE name LIKE '%a%a%a%'

8.India and Angola have an n as the second character. You can use the underscore as a single character wildcard.

SELECT name FROM worldWHERE name LIKE '_n%'
ORDER BY name

Find the countries that have “t” as the second character.

SELECT name FROM worldWHERE name LIKE '_t%'
ORDER BY name

9.Lesotho and Moldova both have two o characters separated by two other characters.

Find the countries that have two “o” characters separated by two others.

SELECT name FROM worldWHERE name LIKE '%o__o%'

10.Cuba and Togo have four characters names.

Find the countries that have exactly four characters.

SELECT name FROM worldWHERE name LIKE '____'

11.The capital of Luxembourg is Luxembourg. Show all the countries where the capital is the same as the name of the country

Find the country where the name is the capital city.

SELECT nameFROM worldWHERE name = capital

12.The capital of Mexico is Mexico City. Show all the countries where the capital has the country together with the word “City”.

Find the country where the capital is the country plus “City”.

SELECT nameFROM worldWHERE capital = concat(name, ' City')

13.Find the capital and the name where the capital includes the name of the country.

SELECT capital, name 
FROM world 
WHERE capital  LIKE concat('%',name,'%')

14.Find the capital and the name where the capital is an extension of name of the country.

You should include Mexico City as it is longer than Mexico. You should not include Luxembourg as the capital is the same as the country.

SELECT capital,name
FROM world 
WHERE capital LIKE concat(name,'_%')

15

For Monaco-Ville the name is Monaco and the extension is -Ville.
Show the name and the extension where the capital is an extension of name of the country.
You can use the SQL function REPLACE.

select name,replace(capital, name, '') from  world 
where capital like concat(name,'%_')

这篇关于SQL ZOO 练习 —— SELECT names的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/399396

相关文章

通过ibd文件恢复MySql数据的操作方法

《通过ibd文件恢复MySql数据的操作方法》文章介绍通过.ibd文件恢复MySQL数据的过程,包括知道表结构和不知道表结构两种情况,对于知道表结构的情况,可以直接将.ibd文件复制到新的数据库目录并... 目录第一种情况:知道表结构第二种情况:不知道表结构总结今天干了一件大事,安装1Panel导致原来服务

mysql关联查询速度慢的问题及解决

《mysql关联查询速度慢的问题及解决》:本文主要介绍mysql关联查询速度慢的问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql关联查询速度慢1. 记录原因1.1 在一次线上的服务中1.2 最终发现2. 解决方案3. 具体操作总结mysql

Linux搭建Mysql主从同步的教程

《Linux搭建Mysql主从同步的教程》:本文主要介绍Linux搭建Mysql主从同步的教程,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录linux搭建mysql主从同步1.启动mysql服务2.修改Mysql主库配置文件/etc/my.cnf3.重启主库my

MySql中的数据库连接池详解

《MySql中的数据库连接池详解》:本文主要介绍MySql中的数据库连接池方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录mysql数据库连接池1、概念2、为什么会出现数据库连接池3、原理4、数据库连接池的提供商5、DataSource数据源6、DBCP7、C

MySQL的隐式锁(Implicit Lock)原理实现

《MySQL的隐式锁(ImplicitLock)原理实现》MySQL的InnoDB存储引擎中隐式锁是一种自动管理的锁,用于保证事务在行级别操作时的数据一致性和安全性,本文主要介绍了MySQL的隐式锁... 目录1. 背景:什么是隐式锁?2. 隐式锁的工作原理3. 隐式锁的类型4. 隐式锁的实现与源代码分析4

MySQL中Next-Key Lock底层原理实现

《MySQL中Next-KeyLock底层原理实现》Next-KeyLock是MySQLInnoDB存储引擎中的一种锁机制,结合记录锁和间隙锁,用于高效并发控制并避免幻读,本文主要介绍了MySQL中... 目录一、Next-Key Lock 的定义与作用二、底层原理三、源代码解析四、总结Next-Key L

MySQL常见的存储引擎和区别说明

《MySQL常见的存储引擎和区别说明》MySQL支持多种存储引擎,如InnoDB、MyISAM、MEMORY、Archive、CSV和Blackhole,每种引擎有其特点和适用场景,选择存储引擎时需根... 目录mysql常见的存储引擎和区别说明1. InnoDB2. MyISAM3. MEMORY4. A

Mysql中InnoDB与MyISAM索引差异详解(最新整理)

《Mysql中InnoDB与MyISAM索引差异详解(最新整理)》InnoDB和MyISAM在索引实现和特性上有差异,包括聚集索引、非聚集索引、事务支持、并发控制、覆盖索引、主键约束、外键支持和物理存... 目录1. 索引类型与数据存储方式InnoDBMyISAM2. 事务与并发控制InnoDBMyISAM

MySQL 日期时间格式化函数 DATE_FORMAT() 的使用示例详解

《MySQL日期时间格式化函数DATE_FORMAT()的使用示例详解》`DATE_FORMAT()`是MySQL中用于格式化日期时间的函数,本文详细介绍了其语法、格式化字符串的含义以及常见日期... 目录一、DATE_FORMAT()语法二、格式化字符串详解三、常见日期时间格式组合四、业务场景五、总结一、

mysql线上查询之前要性能调优的技巧及示例

《mysql线上查询之前要性能调优的技巧及示例》文章介绍了查询优化的几种方法,包括使用索引、避免不必要的列和行、有效的JOIN策略、子查询和派生表的优化、查询提示和优化器提示等,这些方法可以帮助提高数... 目录避免不必要的列和行使用有效的JOIN策略使用子查询和派生表时要小心使用查询提示和优化器提示其他常