当前位置:网站首页>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

边栏推荐
- 好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
- Codeblocks + Widgets create window code analysis
- 国轩高科瑞交所上市:募资近7亿美元 为瑞士今年最大融资项目
- 单例模式 (Singleton)
- After 23 years of operation, the former "China's largest e-commerce website" has turned yellow...
- 【HarmonyOS】【FAQ】鸿蒙问题合集3
- 终端分屏工具Terminalx的使用
- Two-point answer naked question (plus a little pigeonhole principle)
- 攻防世界web-Cat
- linux 下MySQL本地安装mysql - u root - p 无法登入
猜你喜欢

软件测试13年从业经验的前辈,总结的5条测试就业建议....
![[Summary] 1396- 60+ VSCode plugins to create a useful editor](/img/e4/65e55d0e4948c011585b72733d4d19.jpg)
[Summary] 1396- 60+ VSCode plugins to create a useful editor

Pytorch foundation -- tensorboard use (1)

CIMC Shilian Dafeitong is the global industrial artificial intelligence AI leader, the world's top AI core technology, high generalization, high robustness, sparse sample continuous learning, industri

MySQL数据类型

Mysql execution principle analysis

Basic use of scrapy

强啊,点赞业务缓存设计优化探索之路。

The large-scale application of artificial intelligence AI products in industrial-grade mature shipping ports of CIMC World Lianda will create a new generation of high-efficiency smart ports and innova

你好,我的新名字叫“铜锁/Tongsuo”
随机推荐
荐号 | 对你有恩的人,不要请吃饭来报答
requet.getHeader(“token“) 为null
NC | 西湖大学陶亮组-TMPRSS2“助攻”病毒感染并介导索氏梭菌出血毒素的宿主入侵...
OneFlow源码解析:Op、Kernel与解释器
linux 下MySQL本地安装mysql - u root - p 无法登入
Pytorch基础--tensorboard使用(一)
时序数据库在船舶风险管理领域的应用
3D机器视觉厂商的场景争夺战役
Critical Reviews | 南农邹建文组综述全球农田土壤抗生素与耐药基因分布
自然语言处理nltk
高精度加法
JVM 上数据处理语言的竞争:Kotlin, Scala 和 SPL
【HarmonyOS】【ARK UI】HarmonyOS ets语言怎么实现双击返回键退出
MYSQL(基本篇)——一篇文章带你走进MYSQL的奇妙世界
What kind of framework is friendly to developers?
EMC VPLEX VS2 SPS电池更换详细探讨
SwiftUI iOS 精品开源项目之 完整烘焙食品菜谱App基于SQLite(教程含源码)
Read the "Language Model" in one article
Mysql execution principle analysis
沉浸式体验科大讯飞2022消博会“官方指定产品”