当前位置:网站首页>Two sorting and one random data fetching of stored procedures
Two sorting and one random data fetching of stored procedures
2022-07-23 11:26:00 【I'm Wang Xi】
sql
Process logic First, according to id Found in reverse order 2000 Data , From here 1000 Find out the data from the largest amount to the smallest amount 100 Data , And this 100 Pieces of data are taken out randomly
CREATE DEFINER=`root`@`%` PROCEDURE `NewProc`()
BEGIN
-- Delete the temporary table if it exists
DROP TABLE IF EXISTS SalesSummary;
CREATE TEMPORARY TABLE SalesSummary (
id INT NOT NULL,
user_id INT NOT NULL DEFAULT 0.00,
money DECIMAL(12,2) NOT NULL DEFAULT 0.00,
remark VARCHAR(50) NOT NULL ,
note VARCHAR(50) NOT NULL,
type TINYINT(3) NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
money_type VARCHAR(1) NOT NULL,
business_id INT NOT NULL,
nickname VARCHAR(50) NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- Delete the temporary table if it exists
DROP TABLE IF EXISTS SalesSummaryB;
CREATE TEMPORARY TABLE SalesSummaryB (
id INT NOT NULL,
user_id INT NOT NULL DEFAULT 0.00,
money DECIMAL(12,2) NOT NULL DEFAULT 0.00,
remark VARCHAR(50) NOT NULL ,
note VARCHAR(50) NOT NULL,
type TINYINT(3) NOT NULL,
created_at TIMESTAMP NOT NULL,
updated_at TIMESTAMP NOT NULL,
money_type VARCHAR(1) NOT NULL,
business_id INT NOT NULL,
nickname VARCHAR(50) NOT NULL
)ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;
-- Put the 100 pieces of data into the temporary table
INSERT INTO SalesSummary select a.id,a.user_id,a.money,a.remark,a.note,a.type,a.created_at,a.updated_at,a.money_type,a.business_id,b.nickname from money_logs as a left join users as b on a.user_id=b.id WHERE `type`=1 or `type`=4 or `type`=5 order by id desc limit 2000;
-- according to money obtain 10 Data to temporary table
INSERT INTO SalesSummaryB select * from SalesSummary order by money desc limit 100;
-- Add fields
ALTER TABLE SalesSummaryB ADD temp_id INT NOT NULL auto_increment primary key;
-- ALTER TABLE SalesSummaryB ADD nickname VARCHAR(50);
-- Randomly disturb all the data in the temporary table
select * from SalesSummaryB order by rand() limit 100;
END
php
$asc = DB::select('call NewProc()');
边栏推荐
- [Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用
- Large factory interview machine learning algorithm (0): Feature Engineering | data preprocessing
- After the formula in word in WPS is copied, there is a picture
- BurpSuite学习笔记
- 通用查询&分页代码
- Spectral clustering | Laplace matrix
- 高阶函数的应用:手写Promise源码(二)
- [python flask notes 5] blueprint is easy to use
- Vite X Figma 打造设计师专属的 i18n 插件
- The tree form based on El table and JS xlsx realize the function of downloading excel (II)
猜你喜欢

TypeScript介绍

C语言中的分支和循环语句归属

Points for attention when using El table to lazy load tree tables

MySQL增删改查&&高级查询语句

py程序可以运行,但打包出的exe运行提示错误:加载“cv2”二进制扩展时检测到递归。请检查OpenCV安装。

When using cache in sprintboot, the data cannot be loaded
![[Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用](/img/6f/e6f5ef79c232d9b27a8334cd8ddaa5.png)
[Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用

Redis database and project framework

The attribution of branch and loop statements in C language
![[pytho-flask笔记5]蓝图简单使用](/img/0a/00b259f42e2fa83d4871263cc5f184.png)
[pytho-flask笔记5]蓝图简单使用
随机推荐
Spectral clustering | Laplace matrix
$attrs中的对象没有变化,但触发了watch监听?
[部署]presto-server-0.261.tar.gz的集群部署和启动
[pytho-flask筆記5]藍圖簡單使用
高阶函数的应用:手写Promise源码(一)
Sequencing, current limiting
Framework introduction Mvt
flex+js实现内部盒子高度跟随其中最大的高度
Spark common interview questions sorting
[metric]使用Prometheus监控flink1.13org.apache.flink.metrics
BurpSuite学习笔记
自定义MVC的使用&增删改查
xtu-ctf Challenges-Reverse 1、2
Niuke question brushing record -- MySQL
频谱聚类|拉普拉斯矩阵
Precautions for realizing "real-time data response" on the page
自定义MVC(上)
Anti shake and throttling of JS
C语言中的流氓goto语句
Web Component-自定義元素的生命周期