当前位置:网站首页>mysql 原生语句点滴学习记录
mysql 原生语句点滴学习记录
2022-08-02 03:26:00 【陌潇】
点滴sql记录
一、IF使用方法
IF 表达式 IF( expr1 , expr2 , expr3 )
expr1 的值为 TRUE,则返回值为 expr2 expr1
的值为FALSE,则返回值为 expr3
如下:

二、group by 分组之后查找重复的项(HAVING)
在 SQL 中增加 HAVING 子句原因是,WHERE 关键字无法与聚合函数一起使用。
HAVING 子句可以让我们筛选分组后的各组数据。
查找phone不为空,且重复的手机号,原始数据:
sql 和执行后的结果:

三、Case两种格式:简单Case函数和Case搜索函数。
1、简单Case函数
case sex
when '1' then '男'
when '2' then '女'
else '其他' end
2、Case搜索函数
case
when sex = '1' then '男'
when sex = '2' then '女'
else '其他' end

case用法详细介绍地址:https://blog.csdn.net/weixin_44688973/article/details/118808601
四、group by分组之后取出最大值
原始数据
使用sql查询: SELECT id, sex, age, max(age) AS age_en FROM USER GROUP BY sex
五、month 和 year 的使用


边栏推荐
猜你喜欢

Praying: 1 vulnhub walkthrough

(1) print()函数、转义字符、二进制与字符编码 、变量、数据类型、input()函数、运算符

PHP deserialization vulnerability

The shooting range that web penetration must play - DVWA shooting range 1 (centos8.2+phpstudy installation environment)

Eric靶机渗透测试通关全教程

元宇宙是一个炒作的科幻概念,还是互联网发展的下半场?

(5) Modules and packages, encoding formats, file operations, directory operations

【泰山众筹】模式为什么一直都这么火热?是有原因的

v-bind usage: class dynamic binding object array style style and function method

hackmyvm-hopper预排
随机推荐
一个网络安全小白鼠的学习之路—nmap高级用法之脚本使用
Solve the problem of Zlibrary stuck/can't find the domain name/reached the limit, the latest address of Zlibrary
hackmyvm: may walkthrough
Summary of php function vulnerabilities
C language uses stack to calculate infix expressions
一次代码审计的笔记(CVE-2018-12613 phpmyadmin文件包含漏洞)
Phonebook
ES6 array extension methods map, filter, reduce, fill and array traversal for…in for…of arr.forEach
Basic use of v-on, parameter passing, modifiers
The focus of the Dom implementation input triggers
PHP反序列化漏洞
DarkHole: 2 vulnhub walkthrough
什么是广告电商商业模式?这几个门派告诉你
PHP realizes the automatic reverse search prompt of the search box
(4) Function, Bug, Class and Object, Encapsulation, Inheritance, Polymorphism, Copy
Alibaba Cloud MySQL 5.7 installation and some major problems (total)
【无标题】
ES6 three-dot operator, array method, string extension method
战场:3(双子叶植物)vulnhub走读
Mysql创建索引