查询
条件判断
select 5种子句:
where 条件查询
group by 分组
having 筛选
order by 排序
limit 限制结果条数
---------------------
where
1.运算符:
<
<=
=
!= <>不等于有两种表示
>=
>
inin (4,5)
betweenbetween 2000 and 3000
取出goods_id是4和5的商品:
select goods_id,goods_name from goods where goods_id in (4,5);
取出goods_price是2000到3000之间的商品:
select goods_price,goods_name from goods where goods_price between 2000 and 3000;
2.逻辑运算符
not 或 !
or 或 ||
and 或 &&
取出goods_price是2000到3000之间的商品,和goods_price是500-1000之间的商品:
select goods_name,goods_price from goods
where goods_price >=2000 and goods_price<=3000 or goods_price >=500 and goods_price <=1000;
3.模糊查询
like "诺基亚%"%是通配任意字符
like "诺基亚N__"_是单个字符
取出所有"诺基亚"开头的商品:
select goods_id,goods_name from goods where goods_name like "诺基亚%";
取出所有"诺基亚NXX"开头的,N后面有两个字符的商品:
select goods_id,goods_name from goods where goods_name like "诺基亚N__";