知识点:
select
查询,可以从表格中选择单列,多列(select name, continent, area from world)和计算(select name, gdp/population as 'per-capita GDP' from world) 显示表格中所有列数据用*符号select * from world
select * from world
select name, continent, area from world
select name, gdp/population as 'per-capita GDP' from world
distinct
去重,select distinct continent from world 显示出表格中的大洲(去掉continent这一列的重复值)
select distinct continent from world
from
接表格名, select name from world 显示表world中name列
select name from world
where
表条件,接在select - from - 后面 select - from - where
=, <, >, <>(不等于)
select name, continent, area from world population>=20000000,显示人口数大于两千万的国家名、所在大洲、和面积大小。
select name, continent, area from world population>=20000000
like
字符表达式%指代任意字符,- 指代一个字符,[]指中括号里面的某个字符,^非 '-[^JM]%' 指第二个字母不是J或M的字符 select name from world where name like '-[^JM]%' 找出表格world中第二个字母不是J或M的国家
select name from world where name like '-[^JM]%'
or, in, and
select name, continent from world where name in ('France','Germany','Italy')显示法国,德国,意大利的国家名和所在大洲名,select name, gdp from world where area>=3000000 or population>=25000000,找出面积大于3000000或者人口数大于250000000的国家及其GDP
select name, gdp from world where area>=3000000 or population>=25000000
oxr的SQL表达
首先明白oxr的含义,其含义是A oxr B 只满足AB其中一个条件的结果即满足条件A不满足条件B,或者满足条件B不满足条件A的结果,不包含既满足条件A又满足条件B的结果; 其次需明白SQL中没有oxr, 故而我们需要知道其在SQL的表达,即为 where (case when A is NULL then 0 else 1 end)^(case when B is NULL then 0 else 1 end)=1
select name, gdp from world where (case when area>=3000000 then 1 else 0 end)^(case when population>=25000000 then 1 else 0 end)=1
错题
错题1 oxr的SQL表达![](https://i-blog.csdnimg.cn/blog_migrate/5efdeeebe1632d65bff0f921159e4527.jpeg)
错题2-条件语句字符表达式
其它错题:
错题答案
错题1答案-OXR的SQL表达
![](https://i-blog.csdnimg.cn/blog_migrate/e116d98ee6c23571e0da8cc68f1200ac.jpeg)
错题2答案-条件语句字符表达式
SELECT name FROM world
where name NOT LIKE '% %' and name like '%a%' and name like '%e%' and name like '%i%' and name like '%o%' and name like '%u%'
其它错题错的点
字符后面少了单引号', 字符表达式是与like相接而不是=