单表查询中一些常用的sql语句

select name,age,id,sex from student

select * from student

-- =等于
-- >大于
-- <小于
-- >=大于等于
-- <=小于等于
-- !=  <>不等于
select * from student where age>20
select * from student where sex="男"
-- 逻辑运算符
-- and 并且
-- or 或者
-- not 取非,主要用在in
select * from student where  age>20 or sex="男" 
-- 关键字
-- between...and...两个值之间  []
-- in 包含
-- is null 为null
select * from student where age between 20 and 24
select * from student where age not in(10,21,25)
select * from student where age is null
delete from student where id in(3,13)

-- 模糊查询
-- like 表示模糊查询,需要配合占位符进行使用
-- 占位符  _表示一位字符  %代表任意位字符
select * from student where name like "_李%"

-- 分页查询
-- limit 限制查询子语句
-- limit a,b   a表示起始索引值 索引值从0开始  b代表查询个数
-- limit b offset a
select * from student limit 5,3

-- page当前是第几页  pageSize一页大小
select * from student limit (page-1)*pageSize,pageSize

select * from student where age >21 limit 1,2
-- 排序
-- order by 列名  desc降序|asc升序  asc可以省略 
-- 排序子语句相对位置在where子语句之后,limit子语句之前
select * from student order by age 
select * from student where age>20 order by age desc limit 0,2
-- 聚合函数|分组函数
-- sum 求和
-- avg 求平均
-- max 取最大值
-- min 取最小值
-- count 取得记录数
-- count(*)表示当前查询表中所有记录的个数
-- count(字段名称)不会统计为Null的记录
select count(*) from student
-- group by 字段名称
select max(age),classid from student group by classid

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值