常用查询条件\分组 group by\having和where的区别\union查询
来源:互联网 发布:下载站源码 编辑:程序博客网 时间:2024/06/18 04:47
(1)in()在某个范围(集合)之间
//获得 商品id 为 3, 5, 7 ,8 这几个商品的信息
select goods_name from ecs_goods where goods_id in(3,5,7,8);
2)Between and 在两个值之间的数据
//查询价格在1000-1500之间的商品信息
select shop_price from ecs_goods
where shop_price between 1000 and 1500;
3)Order by排序 排序方法(升序ASC,降序DESC)
//将 获得的商品按照 价格 由高到低 排序
select shop_price from ecs_goods order by shop_price DESC;
(4)limit限定获得数据的数量
//获得价格最高的前十个商品
select shop_price from ecs_goods
order by shop_price desc limit 10;
limit 偏移量,想要获得的记录数量
//获得价格最高的 十个商品 除掉最高的前十个
select shop_price from ecs_goods
order by shop_price desc limit 10,10;(掠过前面10个取后面的10个)
(5)******合计函数
查询不同分类下商品的数量
select count(*) from ecs_goods group by cat_id;
或:select cat_id,count(cat_id) from ecs_goods group by cat_id;
查询不同分类下价格的总和
select sum(shop_price) from ecs_goods group by cat_id;
计算商品平均价格大于1000的商品分类
mysql> select avg(shop_price) as avg_price from ecs_goods group by cat_id having avg_price >1000;
查询不同商品分类下,价格最高的商品
select goods_name,max(shop_price) from ecs_goods group by cat_id;
查询不同的商品分类下面,商品价格的平均数
select avg(shop_price) from ecs_goods group by cat_id;
(6)union 联合 连接(union可以将多个查询语句连接起来,select1 union select2)
select cat_name from ecs_category where cat_id=1 union select cat_name fr
om ecs_category where parent_id=1;
子查询
select子查询
查询类别为‘GSM手机’的商品
select goods_name from ecs_goods where cat_id=(select cat_id from ecs_ca
tegory where cat_name='GSM手机');
from子查询(必须有别名)
select goods_name from(select * from ecs_goods where cat_id in(3,5)) as t
em_goods where goods_name like '诺基亚%';
- 常用查询条件\分组 group by\having和where的区别\union查询
- 详解在group by分组查询中where 和 having的用法和区别。
- mysql group by内排序的实现以及having和where 条件语句查询的区别
- 分组查询 where, group by ,having
- mysql group by having用法+having where之间的区别+group by按日期分组统计的查询
- mysql group by having用法+having where之间的区别+group by按日期分组统计的查询
- group 分组 查询 栏目下文章 的总数 having where区别
- SQL Server 学习(1)子查询(in,not in)、多表查询、合并表(union、union all)、分组(group by)、分组的条件(having)、虚拟表、标量值函数、外键
- Sql- Group By ,having 分组查询
- select查询中where、group by和having的作用时间介绍
- 查询中where和having的区别
- 分组查询 Group by , Group by all , Having
- DataBase-group by, having 和 where 区别
- GROUP BY,WHERE,HAVING之间的区别和用法
- GROUP BY,WHERE,HAVING之间的区别和用法
- GROUP BY,WHERE,HAVING之间的区别和用法
- GROUP BY,WHERE,HAVING之间的区别和用法
- GROUP BY,WHERE,HAVING之间的区别和用法
- C标准库中字符与数字的转换函数
- 自定义ListView item包含checkbox实现单选和多选
- App应用里应该自动跳转到系统设置界面吗?
- 词法分析——实验过程中遇到的问题
- 子网划分及子网掩码计算方法
- 常用查询条件\分组 group by\having和where的区别\union查询
- TCP 分段和IP分片对比
- 【eoeAndroid社区索引】android 条形码的知识汇总
- The notes of Algorithms ---- Dynamic Programming
- 从技术层次解析“微信收费事件”
- java面试题
- android虚拟按键开发之一(开发环境搭建)
- 解决乱码(注意)
- UVa 10494 - If We Were a Child Again