[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
对于分析人员来讲,Mysql数据库应用最多的是select查询语句,此篇文章主要介绍Mysql数据库的查询语句。
一、单表查询
1.带条件的查询
基本语法:select * from +表名称 +where 条件;
1)范围查询:
eg:where 字段 between 10 and 100;
2)模糊查询
eg:where 字段 like'%不确定%'
备注:%代表多个字符,_下划线代表一个字符,^a代表以a为开头的数据,a$代表以a为结尾的数据,[abc]匹配所包含的任意一个字符。
2.多条件查询
备注:当and和or同时使用时,and优先级高于or。如果想要优先带or的条件,对带or部分条件带括号即可。
3.排序
基本语法:order by 字段。
备注:默认是升序,ASC升序,DESC降序
限制记录数:limit 100
4.聚合函数
count():统计记录数
avg():平均数
max():最大值
min():最小值
sum():求和
5.分组
基本语法:select 字段1,字段2,聚合函数 from +表名称 +group by 字段1,字段2
备注:group by和having 一起使用,主要是对分组结果进行过滤
二、多表关联查询
1.内连接-->inner join
内连接即等值连接,获取两个表中字段匹配关系的记录,可省略写成join,
可理解成集合概念中的“交集”,关联字段同时存在与两表的记录。
2.左连接-->left join
左连接,获取左边主表的全部记录,即便右表没有对应的数据。
3.右连接-->right join
右连接,获取右边主表的全部记录,即便左表没有对应的数据。
4.连接符-->union
union用于连接两个以上的select语句的结果,将结果组合到一个结果集中,并删除重复数据
基本语法:select 字段 from 表1 union [all|distinct] select 字段 from 表2
备注:union 即为 union distinct;若为union
all,即返回带重复数据的结果集;在使用union时,所选出的内容显示会以前面的表的字段名称命名。