当前位置:网站首页>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
边栏推荐
- 高精度加法
- MySQL data types
- Anaconda Navigator卡在loading applications
- 【HarmonyOS】【FAQ】鸿蒙问题合集4
- Mysql执行原理剖析
- ESP8266-Arduino编程实例-HC-SR04超声波传感器驱动
- 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
- Scrapy框架介绍
- 积性函数
- 微信小程序云开发 | 城市信息管理
猜你喜欢
3D机器视觉厂商的场景争夺战役
Kettle--MySQL生产数据库千万、亿级数据量迁移方案及性能优化
【HarmonyOS】【FAQ】鸿蒙问题合集4
The sixteenth issue of eight-part article Balabala said (MQ)
NC | Tao Liang Group of West Lake University - TMPRSS2 "assists" virus infection and mediates the host invasion of Clostridium sothrix hemorrhagic toxin...
运营 23 年,昔日“国内第一大电商网站”黄了...
One year after graduation, I was engaged in software testing and won 11.5k. I didn't lose face to the post-98 generation...
Pytorch基础--tensorboard使用(一)
【AGC】增长服务2-应用内消息示例
【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
随机推荐
【Pointing to Offer】Pointing to Offer 22. The kth node from the bottom in the linked list
Mysql执行原理剖析
kotlin的by lazy
【HarmonyOS】【ARK UI】HarmonyOS ets语言怎么实现双击返回键退出
攻防世界web-Cat
第十六期八股文巴拉巴拉说(MQ篇)
ROS 环境使用第三方动态链接库(.so)文件
ESP8266-Arduino编程实例-DS18B20温度传感器驱动
Recommendation | People who are kind to you, don't repay them by inviting them to eat
Anaconda Navigator stuck on loading applications
【AGC】增长服务2-应用内消息示例
AI基础:图解Transformer
荐号 | 对你有恩的人,不要请吃饭来报答
MYSQL (Basic) - An article takes you into the wonderful world of MYSQL
固定资产可视化智能管理系统
微博广告分布式配置中心的构建与实践(有彩蛋)
Chapter 4 Controlling the Execution Flow
基础架构之Mongo
ESP8266-Arduino programming example-BMP180 air pressure temperature sensor driver
【Pointing to Offer】Pointing to Offer 18. Delete the node of the linked list