Closed mrbone closed 6 years ago
[TOC]
select columns from tables where condition ;
示例:
other examle
select name from animals where (species = 'llama') and (birthdate <= '1998-12-31') and (birthdate >= '1995-1-1')
desc
以下是官方解释
以下是上个视频中介绍的新 select 子句: ... limit count 只返回结果表格的前 count 行。 ... limit count offset skip 返回前 skip 行之后的 count 行。 ... order by columns ... order by columns desc 使用 columns(一列或多列,用逗号分隔)作为排序键对列排序。数字列将按数字顺序排序;字符串列将按字母顺序排序。desc 表示顺序为逆序(desc-结尾的排序)。 ... group by columns 更改集合的行为,例如 max、count 和 sum。对于 group by,集合将为 columns 中的每个唯一值返回一行。
示例:找出 animals 数据库中的所有 species 并按照从多到少排序
insert into animals (name, species, birthdate) values('michy', 'opossum', '2018-01-24');
这两种方案完全等效,但原理稍有不同。
寻找只有一种 species 的列
select species, count(*) as num from animals group by species where num = 1 # wrong!!!
select species, count(*) as num from animals group by species where num = 1 # write
where 和 having 的区别在
where
having
num
示例: 找出动物园中只有一个动物吃的食物。
select food, count(animals.name) as num from animals join diet on animals.species = diet.species group by food having num = 1
select food, count(animals.name) as num from animals, diet where animals.species = diet.species group by food having num = 1
[TOC]
数据类型
String
number
date
select
示例:
other examle
其他限定
desc
表示降序排序以下是官方解释
示例:找出 animals 数据库中的所有 species 并按照从多到少排序
insert
join
这两种方案完全等效,但原理稍有不同。
having
寻找只有一种 species 的列
where
和having
的区别在num
不在 source table 中。示例:
找出动物园中只有一个动物吃的食物。