Mysql快速造1w数据思路:left join笛卡尔积

发布于:2024-09-06 ⋅ 阅读:(61) ⋅ 点赞:(0)

Mysql 造数据:
1、建表,并设置ID为自增主键

CREATE TABLE `mysql8_person` (

`id` bigint NOT NULL AUTO_INCREMENT,

`name` varchar(100) DEFAULT NULL,

`age` varchar(100) DEFAULT NULL,

`gender` varchar(100) DEFAULT NULL,

`address` varchar(100) DEFAULT NULL,

`major` varchar(100) DEFAULT NULL,

`nation` varchar(100) DEFAULT NULL,

`money` varchar(100) DEFAULT NULL,

`create_time` varchar(100) DEFAULT NULL,

`modify_time` varchar(100) DEFAULT NULL,

PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=16522 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;

2、插入原始数据10条

INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('1', 'mysql8_赵1', '66', '男', '山东省济南市高新万达1',    '工商管理', '汉族', '10000.00',  '2024-09-05 12:01:00', '2024-09-05 12:01:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('2', 'mysql8_赵2', '66', '男', '山东省济南市高新万达2',    '工商管理', '汉族', '20000.00',  '2024-09-05 12:02:00', '2024-09-05 12:02:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('3', 'mysql8_赵3', '66', '男', '山东省济南市高新万达3',    '工商管理', '汉族', '30000.00',  '2024-09-05 12:03:00', '2024-09-05 12:03:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('4', 'mysql8_赵4', '66', '男', '山东省济南市高新万达4',    '工商管理', '汉族', '40000.00',  '2024-09-05 12:04:00', '2024-09-05 12:04:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('5', 'mysql8_赵5', '66', '男', '山东省济南市高新万达5',    '工商管理', '汉族', '50000.00',  '2024-09-05 12:05:00', '2024-09-05 12:05:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('6', 'mysql8_赵6', '66', '男', '山东省济南市高新万达6',    '工商管理', '汉族', '60000.00',  '2024-09-05 12:06:00', '2024-09-05 12:06:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('7', 'mysql8_赵7', '66', '男', '山东省济南市高新万达7',    '工商管理', '汉族', '70000.00',  '2024-09-05 12:07:00', '2024-09-05 12:07:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('8', 'mysql8_赵8', '66', '男', '山东省济南市高新万达8',    '工商管理', '汉族', '80000.00',  '2024-09-05 12:08:00', '2024-09-05 12:08:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('9', 'mysql8_赵9', '66', '男', '山东省济南市高新万达9',    '工商管理', '汉族', '90000.00',  '2024-09-05 12:09:00', '2024-09-05 12:09:01');
INSERT INTO test.mysql8_person (id, name, age, gender, address, major, nation, `money`, create_time, modify_time) VALUES ('10', 'mysql8_赵10', '66', '男', '山东省济南市高新万达10', '工商管理', '汉族', '100000.00', '2024-09-05 12:10:00', '2024-09-05 12:10:01');


3、笛卡尔积100条

INSERT
    INTO
    test.mysql8_person (name,
    age,
    gender,
    address,
    major,
    nation,
    `money`,
    create_time,
    modify_time)
select
    'mysql8_赵9',
    '66',
    '男',
    '山东省济南市高新万达',
    '工商管理',
    '汉族',
    '90000.00',
    '2024-09-05 12:09:00',
    '2024-09-05 12:09:01' FROM (
    select
        *
    from
        test.mysql8_person
    limit 10) as t1
left join (
    select
        ''
    from
        test.mysql8_person
    limit 10) as t2 on
    1 = 1;


4、笛卡尔积10000条

INSERT
    INTO
    test.mysql8_person (name,
    age,
    gender,
    address,
    major,
    nation,
    `money`,
    create_time,
    modify_time)
select
    'mysql8_赵9',
    '66',
    '男',
    '山东省济南市高新万达',
    '工商管理',
    '汉族',
    '90000.00',
    '2024-09-05 12:09:00',
    '2024-09-05 12:09:01' FROM (
    select
        *
    from
        test.mysql8_person
    limit 100) as t1
left join (
    select
        ''
    from
        test.mysql8_person
    limit 100) as t2 on
    1 = 1;


5、更新内容

update

test.mysql8_person

set

name = concat('云鼎科技00' ,id),

age = id%100,

gender = id%2,

address = concat('高新万达' ,id),

major = '煤炭产业数据',

nation = '汉族',

`money` = id * 10000,

create_time = now(),

modify_time = now();