查询
select 列1,列2,列3 from 表 where 条件
select查询模型
列是变量
条件可以理解为表达式
比如:
select goods_id,goods_name,shop_price,shop_market_price,shopmarketprice - shopprice from goods where shopmarketprice - shopprice>10
条件查询
我们查询的时候可以加上where条件这样既能取得我们想要的数据
这里做一个简单查询练习
查出满足以下条件的商品
1.1:主键为32的商品
select goods_id,goods_name,shop_price from ecs_goods where goods_id=32;
2.1.2:不属第3栏目的所有商品
select goods_id,cat_id,goods_name,shop_price from ecs_goods where cat_id!=3;
2.1.3:本店价格高于3000元的商品
select goods_id,cat_id,goods_name,shop_price from ecs_goods where shop_price >3000;
2.1.4:本店价格低于或等于100元的商品
select goods_id,cat_id,goods_name,shop_price from ecs_goods where shop_price <=100;
2.1.5:取出第4栏目或第11栏目的商品(不许用or)
select goods_id,cat_id,goods_name,shop_price from ecs_goods
where cat_id in (4,11);
2.1.6:取出100<=价格<=500的商品(不许用and)
select goods_id,cat_id,goods_name,shop_price from ecs_goods
where shop_price between 100 and 500;
2.1.7:取出不属于第3栏目且不属于第11栏目的商品(and,或not in分别实现)
select goods_id,cat_id,goods_name,shop_price from ecs_goods where cat_id!=3 and cat_id!=11;
select goods_id,cat_id,goods_name,shop_price from ecs_goods where cat_id not in (3,11);
2.1.8:取出价格大于100且小于300,或者大于4000且小于5000的商品(and的优先级高于or)
select goods_id,cat_id,goods_name,shop_price from ecs_goods where shop_price>100 and shop_price <300 or shop_price >4000 and shop_price <5000;
2.1.9:取出第3个栏目下面价格<1000或>3000,并且点击量>5的系列商品(注意and的优先级高于or)
select goods_id,cat_id,goods_name,shop_price,click_count from ecs_goods where
cat_id=3 and (shop_price <1000 or shop_price>