前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >MySql规范

MySql规范

作者头像
悠扬前奏
发布2019-05-29 17:19:16
3950
发布2019-05-29 17:19:16
举报

SQL规范: 关键字是大写. SELECT * FROM user;

where 1. 条件比较 <=> 可以判断null值,=是不可以判断null值 < > >= <= != <=>

代码语言:javascript
复制
2. 指定范围:between
    假设:我要找出年龄为30-80的数据
    select * from tb_name where age between 30 and 80;
    
3. 指定集合:in
    假设:我要找出id为1,5,4,8,9
    select id,username,age from tb_name where id in(1,5,4,8,9);
    
4. 模糊匹配like
    NOte:没用,千万不要用,
    %:匹配多个任意字符 .*
    _:匹配任意单个字符
    select * from tb_name where username like "%sdfsdf%"
    
5. 是否为null
    select * from tb_name where name is null
    select * from tb_name where name is not null
    
6. 逻辑运算
    and | or
    
Note: 如果你常用需要where的条件,需要添加索引,增加查询速度

group by 分组 Note:将数据相同的分为一组,然后显示出第一条的数据 select * from tb_name group by sex

代码语言:javascript
复制
max()
min()
count() 注意: count是能统计非null的值
sum()
avg()

having Note: where是对"行"操作,having就是对组进行操作。 having 只能在group by 下进行操作.

代码语言:javascript
复制
假设:我需要分组,条件为性别,年龄大于30的才进行统计。

order by 排序 select * from tb_name order by 字段 [asc,desc]

limit 限制 select * from tb_name limit 偏移数,显示的数量

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.03.19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档