当前位置:网站首页>The use of @ symbol in MySql
The use of @ symbol in MySql
2022-07-30 18:32:00 【Zhong Peng】
MySql中@符号的使用
@符号的作用
@后接变量名,to define a variable,The variable is valid at the statement level,That is, it is always valid in another execution,基本示例如下:
-- 由于通常情况下=Considered an equals comparison operator,Therefore the assignment operator is generally used:=
SELECT @lt:=1, @lt:=@lt+1, @lt:=@lt+1;

实现rownum
-- 由于tmp只有一行,When the two tables are linked by a Cartesian product,The result set is effectively equivalent to an additional column,而由于r变量的特性,Each row is incremented based on the original value
SELECT a.BATCHNO, a.YEAR, @r:=@r+1 FROM m1 a, (SELECT @r:=0) tmp;

实现窗口函数
-- base变量的初值,Cannot be used with window functionspartition byThe grouped enumeration values are the same
-- 实现此功能 row_number() (partition by base order by batchno) rn
-- case when 和 @base:= 的顺序不能颠倒,否则会有问题
SELECT a.BATCHNO, a.YEAR, a.BUDITEM, case when @base=a.BUDITEM then @r:=@r+1 ELSE
@r:=1 END rn, @base:=a.BUDITEM FROM m1 a, (SELECT @r:=1, @base:='') tmp ORDER BY a.buditem

边栏推荐
- EMC VPLEX VS2 SPS电池更换详细探讨
- [OC study notes] attribute keyword
- 【Qt Designer工具的使用】
- Scrapy框架介绍
- Go 系统收集
- Network Basics (3) 01-Basic Concepts of Networks - Protocols, Host Addresses, Paths and Parameters of URL Addresses & 127.0.0.1 Local Loopback Address & View URL IP Address and Access Ping Space + URL
- 6 yuan per catty, why do Japanese companies come to China to collect cigarette butts?
- 第4章 控制执行流程
- 基础架构之Redis
- 【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
猜你喜欢

CCNA-网络汇总 超网(CIDR) 路由最长掩码匹配

6 yuan per catty, why do Japanese companies come to China to collect cigarette butts?

智慧中控屏

OSPF详解(3)

【剑指 Offer】剑指 Offer 22. 链表中倒数第k个节点

A senior with 13 years of experience in software testing, summed up 5 test employment suggestions....

微信小程序云开发 | 城市信息管理

深化校企合作 搭建技术技能人才成长“立交桥”

while,do while,for循环语句

DevEco Studio3.0下载失败,提示An unknown error occurred
随机推荐
【HMS core】【Analytics Kit】【FAQ】如何解决华为分析付费分析中付款金额显示为0的问题?
Anaconda Navigator卡在loading applications
CCNA-子网划分(VLSM)
Fixed asset visualization intelligent management system
kotlin的by lazy
Mysql execution principle analysis
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
Chapter 14 Type Information
Kettle--MySQL生产数据库千万、亿级数据量迁移方案及性能优化
深化校企合作 搭建技术技能人才成长“立交桥”
Two-point answer naked question (plus a little pigeonhole principle)
Pytorch foundation -- tensorboard use (1)
The sixteenth issue of eight-part article Balabala said (MQ)
银行适用:此文能够突破你的运维流程管理问题
A senior with 13 years of experience in software testing, summed up 5 test employment suggestions....
Quickly build an e-commerce platform based on Amazon cloud technology serverless service - performance
Basic use of scrapy
第4章 控制执行流程
毕业1年从事软件测试拿下11.5k,没有给98后丢脸吧...
你好好想想,你真的需要配置中心吗?