mysql五大子句实例
1、运用navicat新建查询界面,以下采用该界面查询五大子句;
查询语句顺序:from、where、group by、聚合、having、order by、limit



2、采用mysql系统自带数据库中的表ecs_goods截图演示。

3、where 子句语法如下:
作用:使用比较运算符作为条件
格式:select 字段名1,字段名2… from 表名 where 条件;
例:select * from ecs_goods where cat_id=3;
查询cat_id=3的条目

4、group by子句的使用:
作用:group by子句的作用是对数据进行分组
格式:select 要查找的内容 from 表名 group by 字段名;
例:select * from ecs_goods where cat_id=3 group by goods_name;
(运用group by前,索爱C702c显示两条数据;运用group by后,显示一条汇总数据)
按goods_name列 汇总


5、order by子句的使用:
作用:对查询出来的数据进行排序
格式:select 查询的内容 from 表名 order by 字段1 排序方式,字段2排序方式…;
例:select * from ecs_goods order by cat_id desc;
按cat_id列,倒序排序

6、having子句的使用
作用:具有根据条件对数据进行过滤的作用,having必须用在在group by之后
格式:select 要查找的内容 from 表名 group by 字段名 having 条件;
例:select * from ecs_goods where cat_id=3 group by goods_name HAVING goods_number>12;
筛选goods_number>12的条目

7、limit子句的使用:
作用:限制显示搜索到的数据的条目数
格式:select 查询的内容 from 表名 limit 编号,条目数;
例:select * from ecs_goods where cat_id=3 group by goods_name HAVING goods_number>12 limit 1;
限制一条查询条目
