当前位置:网站首页>Chapter 5 Advanced SQL Processing
Chapter 5 Advanced SQL Processing
2022-07-30 16:34:00 【sand in changsha】
Q1
SELECT product_id
,product_name
,sale_price
,MAX(sale_price) OVER (ORDER BY product_id) AS Current_max_price
FROM product
Q2
SELECT regist_date, product_name, sale_price,
SUM(sale_price) OVER (ORDER BY COALESCE(regist_date, CAST('0001-01-01' AS DATE)))
FROM Product;
Q3
(1)排序,Add a new column to display
根据order by的排序结果,A new column is displayed by the aggregate function used
(2)selectThe purpose is to perform intra-group sorting or aggregation operations without changing the number of data items,order by 中也可用,But it doesn't actually make sense,Just sort by the field you want to sort by
Q4
-- 1.Dynamically create multiple table stored procedures:
DELIMITER $$
DROP PROCEDURE IF EXISTS world.p
CREATE DEFINER=`root`@`localhost` PROCEDURE `world`.`p`()
BEGIN
DECLARE i INT;
DECLARE table_name VARCHAR(20);
DECLARE table_pre VARCHAR(20);
DECLARE sql_text VARCHAR(2000);
SET i=1;
SET table_name='';
SET table_pre='table';
SET sql_text='';
WHILE i<21 DO
IF i<10 THEN SET table_name=CONCAT(table_pre,'0',i);
ELSE SET table_name=CONCAT(table_pre,i);
END IF;
SET sql_text=CONCAT('CREATE TABLE ', table_name, '(product_id CHAR(4) NOT NULL, product_name VARCHAR(100) NOT NULL, product_type VARCHAR(32) NOT NULL, sale_price INTEGER , purchase_price INTEGER , regist_date DATE , PRIMARY KEY (product_id))');
SELECT sql_text;
SET @sql_text=sql_text;
PREPARE stmt FROM @sql_text;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET i=i+1;
END WHILE;
END$$
DELIMITER ;
-- 2.执行存储过程,创建表
CALL p();
边栏推荐
- 【HMS core】【Media】【视频编辑服务】 在线素材无法展示,一直Loading状态或是网络异常
- Recent learning defragmentation (24)
- (1) Cloud computing technology learning - virtualized vSphere learning
- 支付系统架构设计详解,精彩!
- 基于STM32F407使用ADC采集电压实验
- 新人学习小熊派网络应用开发
- Promise笔记(一)
- [HMS core] [FAQ] Collection of typical problems of push kit, AR Engine, advertising service, scanning service 2
- Nervegrowold d2l (7) kaggle housing forecast model, numerical stability and the initialization and activation function
- 字符串加千分位符与递归数组求和
猜你喜欢
![[AGC] Quality Service 1 - Example of Crash Service](/img/d8/e6b365889449745a61597b668dc89b.png)
[AGC] Quality Service 1 - Example of Crash Service
![[AGC] Quality Service 2 - Performance Management Example](/img/09/4a7c57f5aa651e4ac58d1e6d73afe6.png)
[AGC] Quality Service 2 - Performance Management Example

Placement Rules usage documentation

rscsa笔记八

安全业务收入增速超70% 三六零筑牢数字安全龙头

SocialFi 何以成就 Web3 去中心化社交未来

【HMS core】【FAQ】A collection of typical questions about Account, IAP, Location Kit and HarmonyOS 1

3D激光SLAM:LeGO-LOAM论文解读---实验对比

华为云数据治理生产线DataArts,让“数据‘慧’说话”

【HMS core】【FAQ】push kit、分析服务、视频编辑服务典型问题合集3
随机推荐
[Developers must see] [push kit] Collection of typical problems of push service 2
涨姿势了!原来这才是多线程正确实现方式
PyQt5快速开发与实战 9.2 数据库处理
PCIE入门
How to remove last character from string in php
PHP留言反馈管理系统源码
如何注册域名、备案以及解析
How to remove first character from php string
DTSE Tech Talk丨第2期:1小时深度解读SaaS应用系统设计
云风:不加班、不炫技,把复杂的问题简单化
Jetpack Compose 到底优秀在哪里?| 开发者说·DTalk
游戏多开检测的几种实现方法及破解方法参考
深度学习区分不同种类的图片
Qt 动态库与静态库
游戏窗口化的逆向分析
【SOC FPGA】外设KEY点LED
李沐d2l(七)kaggle房价预测+数值稳定性+模型初始化和激活函数
详解最实用的几种dll注入方式
23. Please talk about the difference between IO synchronization, asynchronous, blocking and non-blocking
3D激光SLAM:LeGO-LOAM论文解读---激光雷达里程计与建图