like: 在执行模糊查询时,必须使用like来作为匹配条件
– 语法: select * from 表名 where 字段 like '%关键字%
– 查询名字中带有李的
– select * from student where username like ‘%李%’
– 查询名字的最后一个字是祥的
– select * from student where username like ‘%祥’
– 统计查询(最大值、最小值、平均值、总和、总记录数)
– 查询最大的年龄
– select max(age) from student
– 查询最小的年龄
– select min(age) from student
– 查询年龄的平均值
– select avg(age) from student
– 查询年龄的总和(所有人的年龄加到一起)
– select sum(age) from student
– 重点:查询总记录数(一共有多少条数据)
– select count(*) from student
– 可以为查询到的字段定义别名
– select id,username from student
– select id as abc, username as hello from student
– select id abc, username hello from student
select count(*) total from student
– 语法:select * from student order by 字段 [asc/desc]
– asc 默认就是 asc,表示升序(从小到大排序)
– desc ,表示降序(从大到小排序)
select * from student where sex=‘男’ order by age desc
限制查询结果(类似于截取查询结果)
– 语法:select * from student limit 起始位置, 长度
– select * from student limit 0, 3