mysql查询语句select用法

时间:2024-10-13 01:12:04

1、查询所有表中的数据:select * from 表名称;*:“*”这个符号是表示表中的所有字段。例如:select * from shangpinxinxi;数据如下图

mysql查询语句select用法

2、你可以显示指定的字段:select 字段1,字段2…… from 表名;例如:select fenei, mingcheng,danwei,jiage from shangpinxinxi;

mysql查询语句select用法

3、加条件的查询:select 字段1,字段2…… from 表名 where 条件;例如:select * from shangpinxinxi where left(fenlei,2)='03';分类前2个字符为"03"的数据显示出来

mysql查询语句select用法

4、把重复的数据过滤掉:select distinct 字目愿硅囫段1,字段2…… from 表名;select distinct 字段1 from 表砘捃坑聒名;把字段1的重复的数据过滤掉。select distinct 字段1,字段2…… from 表名;把字段1+字段2的重复的数据过滤掉。例如:select distinct mingcheng from shangpinxinxi;把名称一样的,只显示一个

mysql查询语句select用法

5、查询记录限制显示行数:select * from 表 limit m,n;m:是记录行号 n:是显示多少数据。例如:select * from limit 4; 前4个数据

mysql查询语句select用法

6、查询记录从0,1,2,3,4,……排列,limit 4,3 :是第5条开始显示3个数据select * from limit 4,3;

mysql查询语句select用法

7、查询记录的排序:select * from 表 order by 字段 asc升序,desc降序例如:select * from shangpinxinxi order by mingcheng asc;select * from shangpinxinxi order by jiage desc;

mysql查询语句select用法
mysql查询语句select用法

8、字段的聚合:sum() 相加 count(*)个数 min()最小 max()最大select from 表 group 芟鲠阻缒by 字段[with rollup] [having 条件];例如:select sum(jiage),sum(hyjiage) from shangpinxinxi group by mingcheng;select mingcheng ,sum(jiage),count(*) from shangpinxinxi group by mingcheng;

mysql查询语句select用法
mysql查询语句select用法
© 手抄报圈