当前位置:网站首页>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(基本篇)——一篇文章带你走进MYSQL的奇妙世界
- 《痞子衡嵌入式半月刊》 第 59 期
- Deepen school-enterprise cooperation and build an "overpass" for the growth of technical and skilled talents
- CMake库搜索函数居然不搜索LD_LIBRARY_PATH
- CCNA-ACL(访问控制列表)标准ACL 扩展ACL 命名ACL
- Pytorch基础--tensorboard使用(一)
- 「Redis应用与深度实践笔记」,深得行业人的心,这还不来看看?
- SwiftUI iOS Boutique Open Source Project Complete Baked Food Recipe App based on SQLite (tutorial including source code)
- 微信小程序云开发 | 城市信息管理
- LeetCode Exercise - Two Questions About Finding Sum of Array Elements
猜你喜欢

【PHPWord】PHPOffice 套件之PHPWord快速入门

这玩意儿都能优化?果然是细节都在魔鬼里。

【HMS core】【FAQ】HMS Toolkit典型问题合集1

【HMS core】【ML Kit】机器学习服务常见问题FAQ(二)

【PHPWord】Quick Start of PHPWord in PHPOffice Suite

Recommendation | People who are kind to you, don't repay them by inviting them to eat

Critical Reviews | A review of the global distribution of antibiotics and resistance genes in farmland soil by Nannong Zou Jianwen's group

Meta元宇宙部门第二季度亏损28亿!仍要继续押注?元宇宙发展尚未看到出路!

C# wpf 无边框窗口添加阴影效果

Pagoda builds PHP adaptive lazy website navigation source code measurement
随机推荐
3D机器视觉厂商的场景争夺战役
怎么样的框架对于开发者是友好的?
中集世联达工业级成熟航运港口人工智能AI产品规模化应用,打造新一代高效能智慧港口和创新数字港口,全球港航人工智能能领军者中集飞瞳
Web结题报告
Fixed asset visualization intelligent management system
OSPF详解(3)
ESP8266-Arduino programming example-HC-SR04 ultrasonic sensor driver
【开发者必看】【push kit】推送服务典型问题合集3
时序数据库在船舶风险管理领域的应用
DevEco Studio3.0下载失败,提示An unknown error occurred
沉浸式体验科大讯飞2022消博会“官方指定产品”
好未来单季营收2.24亿美元:同比降84% 张邦鑫持股26.3%
natural language processing nltk
荐书 | 推荐好评如潮的3本数据库书籍
Meta元宇宙部门第二季度亏损28亿!仍要继续押注?元宇宙发展尚未看到出路!
【剑指 Offe】剑指 Offer 17. 打印从1到最大的n位数
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
6块钱1斤,日本公司为何来中国收烟头?
Hello, my new name is "Bronze Lock/Tongsuo"
轻量级网络 ESPNetv2