mysql数据库栏目_mysql数据库的基础(二)

本文详细介绍了MySQL数据库的查询操作,包括基本的SELECT语句、条件查询、分组查询、聚合函数、HAVING子句、ORDER BY排序、LIMIT限制和子查询等,通过实例演示了各种查询技巧,帮助读者掌握数据库查询技能。
摘要由CSDN通过智能技术生成

查询

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条件这样既能取得我们想要的数据

125f2a049c948f732c7d275714ed1db8.png

这里做一个简单查询练习

b07773cd6fedc1b6e439ab7a827f1535.png

查出满足以下条件的商品

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>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值