IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> 设计为多个记录按一个总量来分配 -> 正文阅读

[大数据]设计为多个记录按一个总量来分配

/*
?Navicat Premium Data Transfer

?Source Server ? ? ? ? : overseawmsomsdev
?Source Server Type ? ?: MySQL
?Source Server Version : 80026
?Source Host ? ? ? ? ? : localhost:3306
?Source Schema ? ? ? ? : mytest

?Target Server Type ? ?: MySQL
?Target Server Version : 80026
?File Encoding ? ? ? ? : 65001

?Date: 26/11/2021 20:53:30
*/

SET NAMES utf8mb4;

-- ----------------------------
-- Table structure for ta
-- ----------------------------
DROP TABLE IF EXISTS `ta`;
CREATE TABLE `ta` ?(
? `id` int(0) NOT NULL,
? `gp` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
? `need_qty` int(0) NULL DEFAULT NULL,
? PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of ta
-- ----------------------------
INSERT INTO `ta` VALUES (1, 'A', 50);
INSERT INTO `ta` VALUES (2, 'A', 20);
INSERT INTO `ta` VALUES (3, 'A', 30);
INSERT INTO `ta` VALUES (4, 'B', 100);
INSERT INTO `ta` VALUES (5, 'B', 20);
INSERT INTO `ta` VALUES (6, 'B', 30);
INSERT INTO `ta` VALUES (7, 'C', 50);
INSERT INTO `ta` VALUES (8, 'C', 60);
INSERT INTO `ta` VALUES (9, 'A', 50);
INSERT INTO `ta` VALUES (10, 'C', 60);
INSERT INTO `ta` VALUES (11, 'D', 20);
INSERT INTO `ta` VALUES (12, 'D', 50);
INSERT INTO `ta` VALUES (13, 'E', 20);
INSERT INTO `ta` VALUES (14, 'E', 10);

-- ----------------------------
-- Table structure for tg
-- ----------------------------
DROP TABLE IF EXISTS `tg`;
CREATE TABLE `tg` ?(
? `gp` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
? `ass_qty` int(0) NULL DEFAULT NULL,
? PRIMARY KEY (`gp`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Records of tg
-- ----------------------------
INSERT INTO `tg` VALUES ('A', 80);
INSERT INTO `tg` VALUES ('B', 130);
INSERT INTO `tg` VALUES ('C', 50);
INSERT INTO `tg` VALUES ('D', 70);
INSERT INTO `tg` VALUES ('E', 50);
?? ??? ??? ?
?? ??? ??? ?-- Ass_Qty大于0的即为能分配到数量的记录,小于等于0的未分配到数量,
?? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ??? ?select a.id,a.gp,a.need_qty,b.ass_qty,b.ass_qty- ifnull((select sum(need_qty) from ta where a.gp = gp and id <= a.id group by gp),0) as tt,?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ??? ?case when b.ass_qty-ifnull((select sum(need_qty) from ta where a.gp = gp and id <= a.id group by gp),0)>= 0?
?? ??? ??? ??? ??? ??? ??? ??? ??? ?then a.need_qty else?
?? ??? ??? ??? ??? ??? ??? ??? ?a.need_qty+(b.ass_qty- ifnull((select sum(need_qty) from ta where a.gp = gp and id <= a.id group by gp),0))
?? ??? ??? ??? ??? ??? ??? ??? ?end?
?? ??? ??? ??? ??? ??? ??? ??? ??? ?as Ass_Qty
?? ??? ??? ??? ??? ??? ??? ??? ??? ?from ta as a inner join tg as b on a.gp =b.gp
?? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ?select a.id,a.gp,a.need_qty,b.ass_qty,b.ass_qty- ifnull((select sum(need_qty) from ta where a.gp = gp and id <= a.id group by gp),0) as tt,?? ??? ??? ??? ??? ??? ??? ??? ??? ??? ?
?? ??? ??? ??? ??? ??? ??? ??? ?case when b.ass_qty-ifnull((select sum(need_qty) from ta where a.gp = gp and id <= a.id group by gp),0)> 0?
?? ??? ??? ??? ??? ??? ??? ??? ??? ?then a.need_qty else?
?? ??? ??? ??? ??? ??? ??? ??? ?if(b.ass_qty - ifnull((select sum(need_qty) from ta where a.gp = gp and id <a.id group by gp),0)>0,b.ass_qty - ifnull((select sum(need_qty) from ta where a.gp = gp and id <a.id group by gp),0),0)?? ?
?? ??? ??? ??? ??? ??? ??? ??? ?end?
?? ??? ??? ??? ??? ??? ??? ??? ??? ?as Ass_Qty
?? ??? ??? ??? ??? ??? ??? ??? ??? ?from ta as a inner join tg as b on a.gp =b.gp
?? ??? ??? ?
?? ??? ??? ?
?? ??? ??? ??? ?select a.id,a.gp,a.need_qty,b.ass_qty,b.ass_qty-(select sum(need_qty) from ta where a.gp = gp and id <= a.id group by gp) as tt,
?? ??? ??? ??? ?b.ass_qty-ifnull((select sum(need_qty) from ta where a.gp = gp and id < a.id group by gp),0) as tt1,
?? ??? ??? ?case when b.ass_qty- (select sum(need_qty) from ta where a.gp = gp and id <= a.id group by gp)> 0?
?? ??? ??? ?then a.need_qty else?
?? ?b.ass_qty - ifnull((select sum(need_qty) from ta where a.gp = gp and id < a.id group by gp),0)?? ?
?? ??? ?end?
?? ??? ??? ?as Ass_Qty
?? ??? ??? ?from ta as a inner join tg as b on a.gp =b.gp?? ?


?

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-11-27 09:57:56  更:2021-11-27 09:59:54 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/24 7:57:27-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码