查询

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值