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 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> mysql查询 -> 正文阅读

[大数据]mysql查询

DROP TABLE record_batch;
CREATE TABLE record_batch
(
    id             varchar(16) NOT NULL,
    supplier_count int         NOT NULL,
    employee_count int         NOT NULL,
    start_date     date DEFAULT NULL,
    end_date       date DEFAULT NULL
);
DROP TABLE record_summary;
CREATE TABLE record_summary
(
    id          int         NOT NULL PRIMARY KEY AUTO_INCREMENT,
    batch_id    varchar(16) NOT NULL,
    supplier_id varchar(16) NOT NULL,
    employee_id varchar(16) NOT NULL,
    work_days   float       NOT NULL,
    over_times  float       NOT NULL
);
DROP TABLE record;
CREATE TABLE record
(
    id          varchar(16) NOT NULL,
    batch_id    varchar(16) NOT NULL,
    supplier_id varchar(16) NOT NULL,
    employee_id varchar(16) NOT NULL,
    record_date date        NOT NULL,
    record_days float       NOT NULL,
    over_times  float       NOT NULL,
    create_time datetime DEFAULT now()
);

INSERT INTO record VALUES ('record_1', 'batch_1', 'supplier_1', 'employee_1', '2021/10/10', 1, 1, now());
INSERT INTO record VALUES ('record_2', 'batch_1', 'supplier_1', 'employee_1', '2021/10/11', 1, 1, now());
INSERT INTO record VALUES ('record_3', 'batch_1', 'supplier_1', 'employee_1', '2021/10/12', 1, 1, now());
INSERT INTO record VALUES ('record_4', 'batch_1', 'supplier_1', 'employee_1', '2021/10/13', 1, 1, now());
INSERT INTO record VALUES ('record_5', 'batch_1', 'supplier_1', 'employee_1', '2021/10/14', 1, 1, now());
INSERT INTO record VALUES ('record_6', 'batch_1', 'supplier_1', 'employee_1', '2021/10/15', 1, 1, now());
INSERT INTO record VALUES ('record_7', 'batch_1', 'supplier_1', 'employee_1', '2021/10/16', 0, 0, now());

INSERT INTO record VALUES ('record_8', 'batch_1', 'supplier_1', 'employee_2', '2021/10/10', 1, 1, now());
INSERT INTO record VALUES ('record_9', 'batch_1', 'supplier_1', 'employee_2', '2021/10/11', 1, 1, now());
INSERT INTO record VALUES ('record_10', 'batch_1', 'supplier_1', 'employee_2', '2021/10/12', 1, 1, now());
INSERT INTO record VALUES ('record_11', 'batch_1', 'supplier_1', 'employee_2', '2021/10/13', 1, 1, now());
INSERT INTO record VALUES ('record_12', 'batch_1', 'supplier_1', 'employee_2', '2021/10/14', 1, 1, now());
INSERT INTO record VALUES ('record_13', 'batch_1', 'supplier_1', 'employee_2', '2021/10/15', 0, 0, now());
INSERT INTO record VALUES ('record_14', 'batch_1', 'supplier_1', 'employee_2', '2021/10/16', 0, 0, now());

INSERT INTO record VALUES ('record_15', 'batch_1', 'supplier_1', 'employee_3', '2021/10/10', 1, 1, now());
INSERT INTO record VALUES ('record_16', 'batch_1', 'supplier_1', 'employee_3', '2021/10/11', 1, 1, now());
INSERT INTO record VALUES ('record_17', 'batch_1', 'supplier_1', 'employee_3', '2021/10/12', 1, 1, now());
INSERT INTO record VALUES ('record_18', 'batch_1', 'supplier_1', 'employee_3', '2021/10/13', 1, 1, now());
INSERT INTO record VALUES ('record_19', 'batch_1', 'supplier_1', 'employee_3', '2021/10/14', 1, 1, now());
INSERT INTO record VALUES ('record_20', 'batch_1', 'supplier_1', 'employee_3', '2021/10/15', 0, 0, now());
INSERT INTO record VALUES ('record_21', 'batch_1', 'supplier_1', 'employee_3', '2021/10/16', 0, 0, now());

INSERT INTO record VALUES ('record_22', 'batch_1', 'supplier_2', 'employee_4', '2021/10/10', 1, 1, now());
INSERT INTO record VALUES ('record_23', 'batch_1', 'supplier_2', 'employee_4', '2021/10/11', 1, 1, now());
INSERT INTO record VALUES ('record_24', 'batch_1', 'supplier_2', 'employee_4', '2021/10/12', 1, 1, now());
INSERT INTO record VALUES ('record_25', 'batch_1', 'supplier_2', 'employee_4', '2021/10/13', 1, 1, now());
INSERT INTO record VALUES ('record_26', 'batch_1', 'supplier_2', 'employee_4', '2021/10/14', 1, 1, now());
INSERT INTO record VALUES ('record_27', 'batch_1', 'supplier_2', 'employee_4', '2021/10/15', 1, 0, now());
INSERT INTO record VALUES ('record_28', 'batch_1', 'supplier_2', 'employee_4', '2021/10/16', 1, 0, now());


INSERT INTO record VALUES ('record_29', 'batch_1', 'supplier_2', 'employee_5', '2021/10/10', 1, 1, now());
INSERT INTO record VALUES ('record_30', 'batch_1', 'supplier_2', 'employee_5', '2021/10/11', 1, 1, now());
INSERT INTO record VALUES ('record_31', 'batch_1', 'supplier_2', 'employee_5', '2021/10/12', 1, 1, now());
INSERT INTO record VALUES ('record_32', 'batch_1', 'supplier_2', 'employee_5', '2021/10/13', 1, 1, now());
INSERT INTO record VALUES ('record_33', 'batch_1', 'supplier_2', 'employee_5', '2021/10/14', 1, 1, now());
INSERT INTO record VALUES ('record_34', 'batch_1', 'supplier_2', 'employee_5', '2021/10/15', 1, 0, now());
INSERT INTO record VALUES ('record_35', 'batch_1', 'supplier_2', 'employee_5', '2021/10/16', 1, 0, now());


INSERT INTO record VALUES ('record_36', 'batch_2', 'supplier_1', 'employee_1', '2021/10/17', 1, 1, now());
INSERT INTO record VALUES ('record_37', 'batch_2', 'supplier_1', 'employee_1', '2021/10/18', 1, 1, now());
INSERT INTO record VALUES ('record_38', 'batch_2', 'supplier_1', 'employee_1', '2021/10/19', 1, 1, now());
INSERT INTO record VALUES ('record_39', 'batch_2', 'supplier_1', 'employee_1', '2021/10/20', 1, 1, now());
INSERT INTO record VALUES ('record_40', 'batch_2', 'supplier_1', 'employee_1', '2021/10/21', 1, 1, now());
INSERT INTO record VALUES ('record_41', 'batch_2', 'supplier_1', 'employee_1', '2021/10/22', 1, 0, now());
INSERT INTO record VALUES ('record_42', 'batch_2', 'supplier_1', 'employee_1', '2021/10/23', 1, 0, now());


INSERT INTO record VALUES ('record_43', 'batch_2', 'supplier_2', 'employee_5', '2021/10/17', 1, 1, now());
INSERT INTO record VALUES ('record_44', 'batch_2', 'supplier_2', 'employee_5', '2021/10/18', 1, 1, now());
INSERT INTO record VALUES ('record_45', 'batch_2', 'supplier_2', 'employee_5', '2021/10/19', 1, 1, now());
INSERT INTO record VALUES ('record_46', 'batch_2', 'supplier_2', 'employee_5', '2021/10/20', 1, 1, now());
INSERT INTO record VALUES ('record_47', 'batch_2', 'supplier_2', 'employee_5', '2021/10/21', 1, 1, now());
INSERT INTO record VALUES ('record_48', 'batch_2', 'supplier_2', 'employee_5', '2021/10/22', 0, 0, now());
INSERT INTO record VALUES ('record_49', 'batch_2', 'supplier_2', 'employee_5', '2021/10/23', 1, 0, now());


INSERT INTO record VALUES ('record_50', 'batch_3', 'supplier_2', 'employee_4', '2021/10/17', 1, 1, now());
INSERT INTO record VALUES ('record_51', 'batch_3', 'supplier_2', 'employee_4', '2021/10/18', 1, 1, now());
INSERT INTO record VALUES ('record_52', 'batch_3', 'supplier_2', 'employee_4', '2021/10/19', 1, 1, now());
INSERT INTO record VALUES ('record_53', 'batch_3', 'supplier_2', 'employee_4', '2021/10/20', 1, 1, now());
INSERT INTO record VALUES ('record_54', 'batch_3', 'supplier_2', 'employee_4', '2021/10/21', 1, 1, now());
INSERT INTO record VALUES ('record_55', 'batch_3', 'supplier_2', 'employee_4', '2021/10/22', 0, 0, now());
INSERT INTO record VALUES ('record_56', 'batch_3', 'supplier_2', 'employee_4', '2021/10/23', 1, 0, now());


INSERT INTO record VALUES ('record_57', 'batch_3', 'supplier_3', 'employee_6', '2021/10/17', 1, 1, now());
INSERT INTO record VALUES ('record_58', 'batch_3', 'supplier_3', 'employee_6', '2021/10/18', 1, 1, now());
INSERT INTO record VALUES ('record_59', 'batch_3', 'supplier_3', 'employee_6', '2021/10/19', 1, 1, now());
INSERT INTO record VALUES ('record_60', 'batch_3', 'supplier_3', 'employee_6', '2021/10/20', 1, 1, now());
INSERT INTO record VALUES ('record_61', 'batch_3', 'supplier_3', 'employee_6', '2021/10/21', 1, 1, now());
INSERT INTO record VALUES ('record_62', 'batch_3', 'supplier_3', 'employee_6', '2021/10/22', 0, 0, now());
INSERT INTO record VALUES ('record_62', 'batch_3', 'supplier_3', 'employee_6', '2021/10/23', 1, 0, now());


INSERT INTO record VALUES ('record_63', 'batch_4', 'supplier_4', 'employee_7', '2021/10/17', 1, 1, now());
INSERT INTO record VALUES ('record_64', 'batch_4', 'supplier_4', 'employee_7', '2021/10/18', 1, 1, now());
INSERT INTO record VALUES ('record_65', 'batch_4', 'supplier_4', 'employee_7', '2021/10/19', 1, 1, now());
INSERT INTO record VALUES ('record_66', 'batch_4', 'supplier_4', 'employee_7', '2021/10/20', 1, 1, now());
INSERT INTO record VALUES ('record_67', 'batch_4', 'supplier_4', 'employee_7', '2021/10/21', 1, 1, now());
INSERT INTO record VALUES ('record_68', 'batch_4', 'supplier_4', 'employee_7', '2021/10/22', 0, 0, now());
INSERT INTO record VALUES ('record_69', 'batch_4', 'supplier_4', 'employee_7', '2021/10/23', 1, 0, now());



INSERT INTO record_batch (id, supplier_count, employee_count)
SELECT
    batch_id,
    COUNT(DISTINCT supplier_id),
    COUNT(DISTINCT employee_id)
FROM
    record
GROUP BY
    batch_id;

INSERT INTO record_summary (batch_id, supplier_id, employee_id, work_days, over_times)
SELECT
    batch_id,
    supplier_id,
    employee_id,
    SUM(record_days),
    SUM(over_times)
FROM
    record
GROUP BY
    employee_id, batch_id;

INSERT INTO record VALUES ('record_70', 'batch_5', 'supplier_4', 'employee_7', '2021/10/10', 1, 1, now());
INSERT INTO record VALUES ('record_71', 'batch_5', 'supplier_4', 'employee_7', '2021/10/11', 1, 1, now());
INSERT INTO record VALUES ('record_72', 'batch_5', 'supplier_4', 'employee_7', '2021/10/12', 1, 1, now());
INSERT INTO record VALUES ('record_73', 'batch_5', 'supplier_4', 'employee_7', '2021/10/13', 1, 1, now());
INSERT INTO record VALUES ('record_74', 'batch_5', 'supplier_4', 'employee_7', '2021/10/14', 1, 1, now());
INSERT INTO record VALUES ('record_75', 'batch_5', 'supplier_4', 'employee_7', '2021/10/15', 0, 0, now());
INSERT INTO record VALUES ('record_76', 'batch_5', 'supplier_4', 'employee_7', '2021/10/16', 1, 0, now());
INSERT INTO record VALUES ('record_77', 'batch_5', 'supplier_4', 'employee_1', '2021/10/09', 1, 0, now());

SELECT
    record.id,
    record.employee_id,
    record.record_date,
    record.batch_id,
    record.record_date,
    batch.supplier_count,
    batch.employee_count
FROM
    record
        INNER JOIN record_batch batch ON record.batch_id = batch.id
WHERE
      record.employee_id = 'employee_7'
  AND record.record_date <= '2021-10-10'
  AND record.record_date >= '2021-10-08';

SELECT
    record.id,
    record.employee_id,
    record.record_date,
    record.batch_id,
    record.record_date,
    record.create_time,
    batch.supplier_count,
    batch.employee_count
FROM
    record
        LEFT JOIN record_batch batch ON record.batch_id = batch.id
WHERE
      record.employee_id = 'employee_7'
  AND record.record_date <= '2021-20-10'
  AND record.record_date >= '2021-10-08'
  AND record.create_time <= '2021/12/04 22:30:00'
AND batch.id IS NULL ;

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-12-05 12:06:24  更:2021-12-05 12:07:12 
 
开发: 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 10:34:56-

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