• 建表,多设置一个字段id_tmp
      create table if not exists mall_data.dtw_mall2_adm_customer_d_tmp(
      id_tmp string comment '临时创建的id',
      mac_addr string comment 'Mac地址',
      customer_id string comment '客户ID',
      name string comment '姓名',
      gender string comment '性别',
      age string comment '年龄',
      phone string comment '手机',
      email string comment '邮箱',
      birthday string comment '生日',
      city string comment '省份城市',
      has_car string comment '是否有车',
      member_id string comment '会员号',
      member_point string comment '会员积分',
      member_status string comment '会员状态',
      member_activate_time string comment '激活时间',
      customer_type string comment '客户类型',
      customer_life_cycle string comment '生命周期',
      customer_new_old string comment '新老客户',
      customer_level string comment '客户等级',
      worth_consume_level string comment '消费层级',
      shopping_feature string comment '购物特征',
      character_all string comment '性格特征',
      food_style string comment '偏好菜系',
      food_price string comment '偏好用餐价位',
      food_taste string comment '偏好口味',
      food_time string comment '偏好用餐时间',
      food_type string comment '偏好餐饮类型',
      mall_visit_times_all string comment '到访次数',
      mall_stay_time_all string comment '总停留时长',
      mall_stay_time_avg string comment '平均停留时长',
      shop_visit_num string comment '到访店铺数',
      shop_stay_time_avg string comment '到店平均停留时长',
      mall_last_visit_time string comment '上次到访时间',
      pay_mall_all string comment '交易总额',
      pay_num_mall_all string comment '交易笔数',
      pay_per_deal_avg string comment '平均每笔交易金额',
      pay_shop_num_all string comment '成交店铺数',
      pay_per_shop_avg string comment '成交店铺平均单价',
      pay_commodity_num_all string comment '成交商品数',
      pay_commodity_per_unit_avg string comment '成交商品平均单价',
      pay_last_time string comment '上次交易时间'
      )
      comment '用户表'
      partitioned by (ds string comment '分区', tenantId int comment '租户id' , mallName string comment '商场名称')
      stored as parquet;
    • 创建临时表 tmp_count_control,用于辅助数据的插入
      create table tmp_count_control(id int);

      insert into table tmp_count_control values(1),(2),(3),(4),(5),(6),(7),(8),(9),(10),(11),(12),(13),(14),(15),(16);

      select * from tmp_count_control;

    • 插入数据到
      insert into mall_data.dtw_mall2_adm_customer_d_tmp partition(ds='20180615', tenantid=1, mallname='big')
      select
      id,
      cast(rand()*1000000 as int)+1000000,
      cast(rand()*1000000 as int)+1000000,
      concat(
      split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
      split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
      split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
      split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
      split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
      split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)],
      split('a b c d e f g h i g k l m n o p q r s t u v w x y z',' ')[cast(rand()*26 as int)]
      ),
      split('m f notclear',' ')[cast((rand()*3) as int)],
      cast((rand()*40) as int)+10,
      13344455666,
      'dtw123@dtw-inc.com',
      concat(concat(199,split('0 1 2 3 4 5 6 7 8 9',' ')[cast(rand()*10 as int)]),
      split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
      concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
      ),
      split('北京 上海 广州 深圳 杭州 厦门 福州 济南 青岛 烟台 济宁 临沂 莱芜 曲阜 平壤 太原 阜阳 合肥 嵊州 平度 拉萨 昆明 沈阳 长春 哈尔滨',' ')[cast(rand()*25 as int)],
      split('有 无 不确定',' ')[cast((rand()*3) as int)],
      cast(rand()*1000000 as int)+1000000,
      cast(rand()*100000 as int),
      split('未激活 已激活',' ')[cast(rand()*2 as int)],
      concat(concat(201,split('0 1 2 3 4 5 6 7',' ')[cast(rand()*8 as int)]),
      split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
      concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
      ),
      split('到访客户 成交客户 会员客户',' ')[cast(rand()*3 as int)],
      split('新客 活跃客户 忠诚客户 流失客户 回头客',' ')[cast(rand()*5 as int)],
      split('新客户 老客户',' ')[cast(rand()*2 as int)],
      split('初级访客 中级访客 高级访客 初级会员 中级会员 高级会员',' ')[cast(rand()*6 as int)],
      split('低 中 高',' ')[cast(rand()*3 as int)],
      concat(
      '{',
      split('花卉一族 摄影一族 健美一族 果粉 电影派 阅读者 舞林人士 乐器迷 爱听音乐 童心未泯',' ')[cast(rand()*10 as int)],
      ',',
      split('御宅族 白富美 高帅富 呼朋唤友 休闲大咖 装修一族 甜蜜新人 户外一族 网络一族 酒品人生',' ')[cast(rand()*10 as int)],
      ',',
      split('有型潮男 拜金主义 数码达人 家有儿女 养生专家 运动一族 车友派 家有宠物 游戏人生 爱家人士',' ')[cast(rand()*10 as int)],
      '}'
      ),
      concat(
      '{',
      split('明确果断 犹豫再三 喜新厌旧 货比三家',' ')[cast(rand()*4 as int)],
      ',',
      split('只逛不买 虚荣型 忠诚型',' ')[cast(rand()*3 as int)],
      ',',
      split('挑剔型 将就型 跟风型',' ')[cast(rand()*3 as int)],
      '}'
      ),
      split('川菜 粤菜 淮扬菜 浙菜 湘菜 徽菜 闽菜 日本菜 台湾菜 韩国菜',' ')[cast(rand()*10 as int)],
      split('低 中 高',' ')[cast(rand()*3 as int)],
      split('油 清淡 辣 麻 咸',' ')[cast(rand()*5 as int)],
      split('上午 中午 下午 黄昏 傍晚 晚上',' ')[cast(rand()*6 as int)],
      split('中餐 西餐 自助餐 小吃快餐 饮品店 面包甜点 火锅 特色菜 烧烤',' ')[cast(rand()*9 as int)],
      cast(rand()*50 as int),
      round(rand()*50,1)+5,
      round(rand()*5,1),
      cast(rand()*10 as int),
      round(rand()*5,1)+1,
      concat(concat(201,split('6 7 8',' ')[cast(rand()*3 as int)]),
      split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
      concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
      ),
      round(rand()*5000,1)+5000,
      cast(rand()*50 as int),
      round(rand()*1000,1)+500,
      cast(rand()*20 as int),
      round(rand()*500,1)+50,
      cast(rand()*20 as int),
      round(rand()*100,1)+50,
      concat(concat(201,split('6 7 8',' ')[cast(rand()*3 as int)]),
      split('01 02 03 04 05 06 07 08 09 10 11 12',' ')[cast(rand()*12 as int)],
      concat(split('0 1 2',' ')[cast(rand()*3 as int)],split('1 2 3 4 5 6 7 8',' ')[cast(rand()*8 as int)])
      )

      from tmp_count_control [limit 5000];

    •   OK,完成数据的插入!!!
    • 通过新建临时表来辅助实现插入数据条数的控制,否则就得通过insert into tablename values (******),(******)......形式,写多次上面蓝色的sql(上面80行sql仅仅插入1条数据)

  

mock数据,尽量随机,1次插入多条的更多相关文章

  1. mock数据,尽量随机,采用中间表的方式实现

    开发平台上的sql不能超过1000行,而为了插入尽可能随机的数据,sql比较长---插入一行数据就需要执行80行sql,因此执行insert into mall_data.dtw_mall2_tmp ...

  2. json-server mock数据

    前言: 项目开发中,影响项目进程的常常是由于在前后端数据交互的开发流程中停滞,前端完成静态页面的开发后,后端迟迟未给到接口.而现在,我们就可以通过根据后端接口字段,建立一个REST风格的API接口,进 ...

  3. vue-cli 本地开发mock数据使用方法

    vue-cli 中可以通过配置 proxyTable 解决开发环境的跨域问题,具体可以参考这篇文章: Vue-cli proxyTable 解决开发环境的跨域问题 如果后端接口尚未开发完成,前端开发一 ...

  4. mock数据(模拟后台数据)

    mock数据(模拟后台数据) - Emily恩 - 博客园 https://www.cnblogs.com/enboke/p/vue.html Mock.js http://mockjs.com/ 前 ...

  5. 用一条mysql语句插入多条数据

    这篇文章主要介绍了在mysql中使用一条sql语句插入多条数据,效率非常高,但是原理其实很简单,希望对大家有所帮助 假如有一个数据表A: id name title addtime 如果需要插入n条数 ...

  6. Electron-vue实战(二)— 请求Mock数据渲染页面

    Electron-vue实战(二)— 请求Mock数据渲染页面 作者:狐狸家的鱼 本文链接 GitHub:sueRimn 一.环境搭建 1.安装Mock.js 如果仅仅用作脱离后台的模拟数据,就安装在 ...

  7. mock 数据 解决方案

    前端工程化之--Mock解决方案   https://www.jianshu.com/p/720b12b5d120 一.为什么要使用mock数据: 1.后端接口数据没有的时候,前端根据接口文档,使用 ...

  8. mysql如果数据不存在,则插入新数据,否则更新的实现方法

    mysql如果数据不存在,则插入新数据,否则更新的实现方法 //如果不存在,则插入新数据 $sql = "INSERT INTO {$ecs->table('cat_lang')} ( ...

  9. SQL---一次插入多条数据【使用Union】

    --做测试的时候使用.--缺点:结果集的数量,类型都要一样.INSERT INTO Student ( StudentID, StudentName, StduentAge, StudentBirth ...

随机推荐

  1. ios和android适配问题总结

    _________________________________________________________________________________ 相关知识点 移动端. 适配(兼容). ...

  2. 一款堪称完美的编程字体Source Code Pro

    对于程序员来说,好的字体应该满足的基本条件: 字母和数字易于分辨,如: 英文字母o 和 阿拉伯数字 0 ,或者 英文字母 l 和 阿拉伯数字 1 ,两个单引号 '' 和双引号 ”. 字体等宽,保持对齐 ...

  3. python学习博客地址集合。。。

    python学习博客地址集合...   老师讲课博客目录 http://www.bootcdn.cn/bootstrap/  bootstrap cdn在线地址 http://www.cnblogs. ...

  4. yumiot的发展历程。

    yumiot,大家可能没有听说过,不过作为物联网行业一颗冉冉升起的新星,大家有必要加深这一方面的了解.我先简单介绍一下这个企业.物联网,作为国家大力扶持的行业,相信大家身边也有很多这样的物联网企业.不 ...

  5. mysql 的快速入门

    1.数据库的操作 1)查看数据库:show databases; 2)使用数据库:use 数据库名: 3)创建数据库:create database 数据库名: 4)查看创建数据库的sql语句:sho ...

  6. better-scroll无法滚动的问题。

    better-scroll无法滚动的问题.1遇见better-scroll(以下简称:BS)无法滚动,可从两方面去考虑.一是层级关系出错,二是计算高度出错.###1,层级关系BS的基本结构是:一个wr ...

  7. 来自C++之父的建议

    You don’t have to know every detail of C++ to write good programs; Focus on programming techniques, ...

  8. Sublime Text 3 安装 Package Control

    1.打开sublime text 3 2.Ctrl+`打开控制台或者View->Show Console菜单打开命令行,输入下面这段代码后按Enter键 import urllib.reques ...

  9. 代码精简工具lombok

    Lombok是一种通过注解的方式减少JAVA实体类中大量冗余代码,诸如get.set以及构造方法等的Java库 一.安装Lombok 步骤一 项目引入lombok插件 1 - 非maven依赖托管项目 ...

  10. 模块四-shutil模块

    shutil模块 高级的文件处理模块 主要是文件的处理,移动,压缩和解压缩 shutil模块的使用方法: shutil.copyfile()#拷贝文件 shutil.copy()#拷贝文件和权限 sh ...