select 字段1,字段2
from 表名
where 过滤条件
WHERE子句,将不满足条件的行过滤掉WHERE子句应紧跟FROM子句DISTINCT去除重复行select 字段1,distinct 字段2 from 表名
DISTINCT是对后面所有列名的组合进行去重LIKE运算符主要用于匹配字符串,通常用于模糊匹配
LIKE运算符通常使用如下通配符% : 匹配0个或多个字符
_ : 只能匹配一个字符
https://www.nowcoder.com/exam/oj/ta?tpId=298

select prod_id,prod_name
from Products
where prod_price = 9.49;

select prod_id,prod_name
from Products
where prod_price >= 9;

select prod_name,prod_price
from Products
where prod_price between 3 and 6
order by prod_price;
select prod_name,prod_price
from Products
where prod_price >= 3 and prod_price <= 6
order by prod_price;

select distinct order_num
from OrderItems
where quantity >= 100;
按照order_num订单号进行分组,分组以后的订单号中最大产品数量>=100的订单号
select order_num
from OrderItems
group by order_num
having max(quantity) >= 100

select vend_name
from Vendors
where vend_country = 'USA' and vend_state = 'CA';


select order_num, prod_id, quantity
from OrderItems
where prod_id in ('BR01','BR02','BR03') and quantity >= 100;

select prod_name, prod_price
from Products
where prod_price between 3 and 6
order by prod_price asc;
select prod_name, prod_price
from Products
where prod_price >= 3 and prod_price <= 6
order by prod_price asc;

SELECT vend_name
FROM Vendors
WHERE vend_country = 'USA' AND vend_state = 'CA'
ORDER BY vend_name;
WHERE和ORDER BY同时出现时,WHERE要紧跟FROM,ORDER BY往后放

select prod_name, prod_desc
from Products
where prod_desc like '%toy%';
select prod_name, prod_desc
from Products
where prod_desc regexp 'toy';

select prod_name, prod_desc
from Products
where prod_desc not like '%toy%'
order by prod_desc desc;

这一题需要注意题目要求,两个LIKE和一个AND
select prod_name, prod_desc
from Products
where prod_desc like '%toy%' and prod_desc like '%carrots%';

注意题目要求,只需要使用三个%和一个LIKE
select prod_name, prod_desc
from Products
where prod_desc like '%toy%carrots%';