mysql基础

本文详细介绍了SQL中的各种查询类型,包括基本条件查询、模糊搜索、分页、排序、聚合函数(如COUNT,SUM,AVG,MIN,MAX)、分组查询以及子查询的使用方法。
摘要由CSDN通过智能技术生成

-- 查询语句
select id,username,phone,total from userinfo
select*from userinfo
-- 基础条件查询语句
select id,username,phone,total from userinfo where id BETWEEN 5 and 8
select id,username,phone,total from userinfo where id in(2,5,8)
select id,username,phone,total from userinfo where id< 2 and total<400
select*from userinfo where id>15 or total>350
-- 模糊查询
Select id,username,phone,total from userinfo where username like"乔%"
select id,username,phone,total from userinfo where username like"%三"
select id,username,phone,total from userinfo where username like "_三"
--分页查询
select*from userinfo limit 0,5
select*from userinfo limit 3,8
select*from userinfo limit 2,6
-- 排序order by asc升序 desc降序
select*from userinfo order by total asc
select*from userinfo order by total desc
-- 聚合函数  count查询有多少条数据
select count(0) from userinfo
select count(phone)from userinfo
-- 总和
select sum(age) from userinfo
-- avg 平均年龄
select avg(total)from userinfo
-- min最小值 max最大值
select id,username,phone,MAX(total) from userinfo
select id,username,phone,min(total) from userinfo
--  分组查询 group by
select gender,count(0) avg(total)from userinfo group by gender
select gender,count(0) avg(total)from userinfo where gender>group by gender HAVING avg(gender)>20
-- 子查询把一个查询结果作为另一个查询条件 嵌套查询
select id,username,phone,total,gender where id in(select id from userinfo where age=75)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值