SQLZOO 复盘 SELECT

本文回顾了SQLZOO中关于SELECT的一些有趣操作,包括使用instr替代like进行搜索,使用XOR实现异或查询,字符串处理函数如ROUND、LENGTH、LEFT,不等于操作符的使用,以及在字符串中插入特殊字符的方法。此外,还探讨了子查询、百分比计算、排序和比较操作在实际问题中的应用,如找到人口比例、最大国家、字母排序等复杂查询。
摘要由CSDN通过智能技术生成

前言:很基础的就不提了,只复盘一些有意思的。

1、Show the countries which have a name that includes the word 'United'

这题基础可以用 like+%   where name like '%United%',但是考虑到like时间较长,可换成instr函数。instr(field,str)返回str在field中的起始下标,0表示没有。not like +% 没有,比如没有空格:not like '% %'

select name from world where instr(name,'United')>0

2、One or the other (but not both);Exclusive OR (XOR). Show the countries that are big by area (more than 3 million) or big by population (more than 250 million) but not both. Show name, population and area.

异或,xor,两条件一真一假则真,同真或同假则假。

select name,population,area from world  where area>=3000000 xor population>=250000000

3、ROUND(f,p) returns f rounded to p decimal places,保留p位小数,p可为负数,p为负数时,取整。如Round this value to the nearest 1000。千位取整,round(a

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值