数据推断

学习目标

  • 知道数据推断的使用场景
  • 使用SQL完成关键指标推断逻辑

1 业务背景:缺失关键指标

  • 疫情期间,一家印度外卖餐厅想通过数据分析,数据挖掘提升销量,但是在历史数据中缺少了很重要的一个维度,用餐人数

    • 每单客人的就餐人数这一信息对于我们优化服务流程,设计套餐都有很大的指导意义
    • 从现在开始改造出餐系统,添加就餐人数字段,但是涉及工作量较大(前后端开发,数据库调整),并且改造完成后需要几个月之后积累了一定的数据量可以进行进一步分析
  • 从现有的数据中可以推理出每单的就餐人数,虽然会存在一定误差,但可以利用全部的历史数据,快速上线

  • 下图是外卖软件提供的选项,这里餐具要多少份就是商家依据餐量提供

2 业务数据介绍

  • 有两家餐厅的业务数据
  • 订单表:
    • Order_Number 订单编号
    • Order_Date 订单日期
    • Item_Name 商品名称
    • Quantity 商品数量
    • Product_Price 商品价格
    • Total_products 订单商品数量
    • restaurant_no 连锁店编号
Order_Number Order_Date Item_Name Quantity Product_Price Total_products restaurant_no
16118 03/08/2019 20:25 Plain Papadum 2 0.8 6 1
16118 03/08/2019 20:25 King Prawn Balti 1 12.95 6 1
16118 03/08/2019 20:25 Garlic Naan 1 2.95 6 1
16118 03/08/2019 20:25 Mushroom Rice 1 3.95 6 1
16118 03/08/2019 20:25 Paneer Tikka Masala 1 8.95 6 1
16118 03/08/2019 20:25 Mango Chutney 1 0.5 6 1
16117 03/08/2019 20:17 Plain Naan 1 2.6 7 1
16117 03/08/2019 20:17 Mushroom Rice 1 3.95 7 1
16117 03/08/2019 20:17 Tandoori Chicken (1/4) 1 4.95 7 1
16117 03/08/2019 20:17 Vindaloo - Lamb 1 7.95 7 1
16117 03/08/2019 20:17 Chapati 1 1.95 7 1
16117 03/08/2019 20:17 Lamb Tikka 1 4.95 7 1
16117 03/08/2019 20:17 Saag Paneer 1 5.95 7 1
16116 03/08/2019 20:09 Aloo Chaat 1 4.95 5 1
  • 菜单表:

    • 商品名称
    • 商品价格
item_name product_price restaurant_id
Achar Chicken 8.95 2
Achar Lamb 8.95 2
Aloo Brinjal 5.95 2
Aloo Chaat 4.95 1
Aloo Chaat 4.95 2
Aloo Dupiaza 5.95 2
Aloo Gobi 5.95 1
Aloo Gobi 5.95 2
Aloo Methi 5.95 1
Aloo Mithy 5.95 2
Aloo Peas 5.95 2

3 基本思路

  • 如何根据上述数据确定就餐人数?

    • 我们可以将菜单数据划分为几类,根据不同类别食物的点单量来推断就餐人数
    • 主食:Naan(囊), Rice(米饭)

    • 饮料:Cola(可乐)COBRA(啤酒)

    • 小吃:samosa(咖喱角)Seekh Kebab (烤串)

    • 酱料:pickle(腌菜) Chutney

  • 主菜: LAMB TIKKA 烤羊肉 Prawn Karahi Masala 咖喱虾

  • 确定推断规则:

    • 1份主食对应1人 (1:1)
    • 1份主菜对应1人 (1:1)
    • 1份饮料对应1人(1:1)
    • 2份小食对应1人 (2:1)
    • 酱料,佐料不做计算(n:0)
  • 规则验证:推断就餐人数

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-2lahNEnJ-1631666622971)(img\indian_food1.png)]

    • 主食一份:naan(1:1) , 饮料一份:酸奶(1:1), 菜酱料 4

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-WM0svMfK-1631666622973)(img\indian-food2.png)]

    • 主食:两份米饭+一份馕饼=3人份

    • 饮料:一份酸奶=1人份

    • 主菜: 3个 = 3人份

    • 小食:1份脆饼+6份菜=0.5*7=3.5人份

    • 佐料&配菜:2份酱料=n*0=0人份

    • 按照四类中取最大值的原则,我们可得这顿饭的就餐人数为

      Max(3人份,3人份,3.5人份,0人份)=3.5人,由于人数不能出现小数,向下取整 = 3人

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GQRayo7J-1631666622974)(img\bear.png)]

    • 上面一餐算几人?

      • 主食:没有
      • 饮料:40瓶啤酒
      • 小食:……
      • 酱料:n*0
      • 按照上述原则 上面一餐推断出来的人数为40人——如果专门以喝酒为目的的聚餐,上述规则推断出来的出错概率很高
      • 这种极端的例子可以验证在数据中的占比,如果占比不大则无太大影响

4 代码实现

  • 使用SQL批量处理数据实现数据推断逻辑

    #mermaid-svg-xGGL6iwGszVExswp .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-xGGL6iwGszVExswp .label text{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .node rect,#mermaid-svg-xGGL6iwGszVExswp .node circle,#mermaid-svg-xGGL6iwGszVExswp .node ellipse,#mermaid-svg-xGGL6iwGszVExswp .node polygon,#mermaid-svg-xGGL6iwGszVExswp .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-xGGL6iwGszVExswp .node .label{text-align:center;fill:#333}#mermaid-svg-xGGL6iwGszVExswp .node.clickable{cursor:pointer}#mermaid-svg-xGGL6iwGszVExswp .arrowheadPath{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-xGGL6iwGszVExswp .flowchart-link{stroke:#333;fill:none}#mermaid-svg-xGGL6iwGszVExswp .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-xGGL6iwGszVExswp .edgeLabel rect{opacity:0.9}#mermaid-svg-xGGL6iwGszVExswp .edgeLabel span{color:#333}#mermaid-svg-xGGL6iwGszVExswp .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-xGGL6iwGszVExswp .cluster text{fill:#333}#mermaid-svg-xGGL6iwGszVExswp div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-xGGL6iwGszVExswp .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-xGGL6iwGszVExswp text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-xGGL6iwGszVExswp .actor-line{stroke:grey}#mermaid-svg-xGGL6iwGszVExswp .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-xGGL6iwGszVExswp .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-xGGL6iwGszVExswp #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-xGGL6iwGszVExswp .sequenceNumber{fill:#fff}#mermaid-svg-xGGL6iwGszVExswp #sequencenumber{fill:#333}#mermaid-svg-xGGL6iwGszVExswp #crosshead path{fill:#333;stroke:#333}#mermaid-svg-xGGL6iwGszVExswp .messageText{fill:#333;stroke:#333}#mermaid-svg-xGGL6iwGszVExswp .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-xGGL6iwGszVExswp .labelText,#mermaid-svg-xGGL6iwGszVExswp .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-xGGL6iwGszVExswp .loopText,#mermaid-svg-xGGL6iwGszVExswp .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-xGGL6iwGszVExswp .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-xGGL6iwGszVExswp .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-xGGL6iwGszVExswp .noteText,#mermaid-svg-xGGL6iwGszVExswp .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-xGGL6iwGszVExswp .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-xGGL6iwGszVExswp .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-xGGL6iwGszVExswp .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-xGGL6iwGszVExswp .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .section{stroke:none;opacity:0.2}#mermaid-svg-xGGL6iwGszVExswp .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-xGGL6iwGszVExswp .section2{fill:#fff400}#mermaid-svg-xGGL6iwGszVExswp .section1,#mermaid-svg-xGGL6iwGszVExswp .section3{fill:#fff;opacity:0.2}#mermaid-svg-xGGL6iwGszVExswp .sectionTitle0{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .sectionTitle1{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .sectionTitle2{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .sectionTitle3{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-xGGL6iwGszVExswp .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .grid path{stroke-width:0}#mermaid-svg-xGGL6iwGszVExswp .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-xGGL6iwGszVExswp .task{stroke-width:2}#mermaid-svg-xGGL6iwGszVExswp .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .taskText:not([font-size]){font-size:11px}#mermaid-svg-xGGL6iwGszVExswp .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-xGGL6iwGszVExswp .task.clickable{cursor:pointer}#mermaid-svg-xGGL6iwGszVExswp .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-xGGL6iwGszVExswp .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-xGGL6iwGszVExswp .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-xGGL6iwGszVExswp .taskText0,#mermaid-svg-xGGL6iwGszVExswp .taskText1,#mermaid-svg-xGGL6iwGszVExswp .taskText2,#mermaid-svg-xGGL6iwGszVExswp .taskText3{fill:#fff}#mermaid-svg-xGGL6iwGszVExswp .task0,#mermaid-svg-xGGL6iwGszVExswp .task1,#mermaid-svg-xGGL6iwGszVExswp .task2,#mermaid-svg-xGGL6iwGszVExswp .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-xGGL6iwGszVExswp .taskTextOutside0,#mermaid-svg-xGGL6iwGszVExswp .taskTextOutside2{fill:#000}#mermaid-svg-xGGL6iwGszVExswp .taskTextOutside1,#mermaid-svg-xGGL6iwGszVExswp .taskTextOutside3{fill:#000}#mermaid-svg-xGGL6iwGszVExswp .active0,#mermaid-svg-xGGL6iwGszVExswp .active1,#mermaid-svg-xGGL6iwGszVExswp .active2,#mermaid-svg-xGGL6iwGszVExswp .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-xGGL6iwGszVExswp .activeText0,#mermaid-svg-xGGL6iwGszVExswp .activeText1,#mermaid-svg-xGGL6iwGszVExswp .activeText2,#mermaid-svg-xGGL6iwGszVExswp .activeText3{fill:#000 !important}#mermaid-svg-xGGL6iwGszVExswp .done0,#mermaid-svg-xGGL6iwGszVExswp .done1,#mermaid-svg-xGGL6iwGszVExswp .done2,#mermaid-svg-xGGL6iwGszVExswp .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-xGGL6iwGszVExswp .doneText0,#mermaid-svg-xGGL6iwGszVExswp .doneText1,#mermaid-svg-xGGL6iwGszVExswp .doneText2,#mermaid-svg-xGGL6iwGszVExswp .doneText3{fill:#000 !important}#mermaid-svg-xGGL6iwGszVExswp .crit0,#mermaid-svg-xGGL6iwGszVExswp .crit1,#mermaid-svg-xGGL6iwGszVExswp .crit2,#mermaid-svg-xGGL6iwGszVExswp .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-xGGL6iwGszVExswp .activeCrit0,#mermaid-svg-xGGL6iwGszVExswp .activeCrit1,#mermaid-svg-xGGL6iwGszVExswp .activeCrit2,#mermaid-svg-xGGL6iwGszVExswp .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-xGGL6iwGszVExswp .doneCrit0,#mermaid-svg-xGGL6iwGszVExswp .doneCrit1,#mermaid-svg-xGGL6iwGszVExswp .doneCrit2,#mermaid-svg-xGGL6iwGszVExswp .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-xGGL6iwGszVExswp .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-xGGL6iwGszVExswp .milestoneText{font-style:italic}#mermaid-svg-xGGL6iwGszVExswp .doneCritText0,#mermaid-svg-xGGL6iwGszVExswp .doneCritText1,#mermaid-svg-xGGL6iwGszVExswp .doneCritText2,#mermaid-svg-xGGL6iwGszVExswp .doneCritText3{fill:#000 !important}#mermaid-svg-xGGL6iwGszVExswp .activeCritText0,#mermaid-svg-xGGL6iwGszVExswp .activeCritText1,#mermaid-svg-xGGL6iwGszVExswp .activeCritText2,#mermaid-svg-xGGL6iwGszVExswp .activeCritText3{fill:#000 !important}#mermaid-svg-xGGL6iwGszVExswp .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-xGGL6iwGszVExswp g.classGroup text .title{font-weight:bolder}#mermaid-svg-xGGL6iwGszVExswp g.clickable{cursor:pointer}#mermaid-svg-xGGL6iwGszVExswp g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-xGGL6iwGszVExswp g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-xGGL6iwGszVExswp .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-xGGL6iwGszVExswp .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-xGGL6iwGszVExswp .dashed-line{stroke-dasharray:3}#mermaid-svg-xGGL6iwGszVExswp #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp .commit-id,#mermaid-svg-xGGL6iwGszVExswp .commit-msg,#mermaid-svg-xGGL6iwGszVExswp .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-xGGL6iwGszVExswp g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-xGGL6iwGszVExswp g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-xGGL6iwGszVExswp g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-xGGL6iwGszVExswp g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-xGGL6iwGszVExswp .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-xGGL6iwGszVExswp .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-xGGL6iwGszVExswp .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-xGGL6iwGszVExswp .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-xGGL6iwGszVExswp .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-xGGL6iwGszVExswp .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-xGGL6iwGszVExswp .edgeLabel text{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-xGGL6iwGszVExswp .node circle.state-start{fill:black;stroke:black}#mermaid-svg-xGGL6iwGszVExswp .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-xGGL6iwGszVExswp #statediagram-barbEnd{fill:#9370db}#mermaid-svg-xGGL6iwGszVExswp .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-xGGL6iwGszVExswp .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-xGGL6iwGszVExswp .statediagram-state .divider{stroke:#9370db}#mermaid-svg-xGGL6iwGszVExswp .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-xGGL6iwGszVExswp .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-xGGL6iwGszVExswp .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-xGGL6iwGszVExswp .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-xGGL6iwGszVExswp .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-xGGL6iwGszVExswp .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-xGGL6iwGszVExswp .note-edge{stroke-dasharray:5}#mermaid-svg-xGGL6iwGszVExswp .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-xGGL6iwGszVExswp .error-icon{fill:#522}#mermaid-svg-xGGL6iwGszVExswp .error-text{fill:#522;stroke:#522}#mermaid-svg-xGGL6iwGszVExswp .edge-thickness-normal{stroke-width:2px}#mermaid-svg-xGGL6iwGszVExswp .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-xGGL6iwGszVExswp .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-xGGL6iwGszVExswp .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-xGGL6iwGszVExswp .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-xGGL6iwGszVExswp .marker{fill:#333}#mermaid-svg-xGGL6iwGszVExswp .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-xGGL6iwGszVExswp {color: rgba(0, 0, 0, 0.75);font: ;}

    判断就餐人数
    统计每单交易的主食数量
    四者取最大值,小数向下取整
    统计每单交易的饮料数量
    统计每单交易的主菜数量
    统计每单交易的小食数量
    酱料不统计

  • SQL作业流程

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-QKiQqh8d-1631666622976)(img\sql2.png)]

  • 原始数据中缺少菜品类别标签,需要先添加菜品类别标签

    • 使用LOCATE 函数 进行字符串匹配,使用CASE WHEN 语句判断不同条件,创建新字段 food_category

      LOCATE 函数介绍: LOCATE(substr,str) 返回 substr 在 str中的位置

      • substr, 要查询的子串
      • str 字段名字 或者 字符串
    DROP TABLE IF EXISTS food_category_table;
    CREATE TABLE food_category_table AS SELECT
    Item_Name AS item_name,
    `Product_Price` AS price,
    Restaurant_id AS restaurant_id,
    CASEWHEN locate( 'Dahi', Item_Name )> 0 THEN '酸奶' WHEN locate( 'wine', Item_Name )> 0 OR locate( 'COBRA', Item_Name )> 0 THEN '酒' WHEN locate( 'water', Item_Name )> 0 OR locate( 'Coke', Item_Name )> 0 OR locate( 'Lemonade', Item_Name )> 0 THEN '饮料' WHEN locate( 'Rice', Item_Name )> 0 THEN '米饭' WHEN locate( 'Chapati', Item_Name )> 0 OR locate( 'Paratha', Item_Name )> 0 OR locate( 'Naan', Item_Name )> 0 OR locate( 'roti', Item_Name )> 0 OR locate( 'Papadum', Item_Name )> 0 THEN '饼' WHEN locate ( 'Main', Item_Name )> 0 THEN '主菜' WHEN locate ( 'Chaat', Item_Name )> 0 OR locate( 'Muttar', Item_Name )> 0 THEN '小吃' WHEN locate( 'Chicken', Item_Name )> 0 THEN '鸡肉类' WHEN locate( 'Lamb', Item_Name )> 0 THEN '羊肉类' WHEN locate( 'Fish', Item_Name )> 0 THEN '鱼肉类' WHEN locate( 'Prawn', Item_Name )> 0 OR locate( 'Jinga', Item_Name )> 0 THEN '虾类' WHEN locate( 'Pakora', Item_Name )> 0 THEN '炸素丸子' WHEN LOCATE( 'Saag', Item_Name )> 0 THEN'绿叶菜胡胡' WHEN locate( 'Paneer', Item_Name )> 0 THEN'芝士菜' WHEN locate( 'Pickle', Item_Name )> 0 OR locate( 'Chutney', Item_Name )> 0 THEN'腌菜' WHEN locate( 'Aloo', Item_Name )> 0 THEN'土豆类' WHEN locate( 'Salad', Item_Name )> 0 THEN'沙拉' WHEN locate( 'Tikka', Item_Name )> 0 THEN'烤串' WHEN locate( 'Chana', Item_Name )> 0 THEN'豆类' WHEN locate( 'Dall', Item_Name )> 0 OR locate( 'Hari Mirch', Item_Name )> 0 THEN'素菜' WHEN locate( 'Puree', Item_Name )> 0 THEN'胡胡' WHEN locate( 'Raitha', Item_Name )> 0 OR locate( 'Raita', Item_Name )> 0 THEN'酸奶沙拉' WHEN locate( 'French Fries', Item_Name )> 0 THEN'炸薯条' WHEN locate( 'Samosa', Item_Name )> 0 THEN'咖喱角' WHEN locate( 'Kehab', Item_Name )> 0 OR locate( 'Kebab', Item_Name )> 0 THEN'烤串(小食)' WHEN locate( 'Bhajee', Item_Name )> 0 OR locate( 'Bhaji', Item_Name )> 0 THEN'油炸蔬菜团' WHEN locate( 'Mushroom', Item_Name )> 0 OR locate( 'Vegetable', Item_Name )> 0 THEN'蔬菜' WHEN locate( 'Starter', Item_Name )> 0 THEN'开胃小吃' WHEN locate( 'Sauce', Item_Name )> 0 THEN'酱' ELSE '咖喱菜' END AS food_category FROMrestaurant_products_price;
    
  • 首先看一下产品明细表,知道我们数据库内现有的产品划分,找到与我们推理时用到的分类之间的差异。

    SELECTcount( DISTINCT item_name ) AS item_num,food_category
    FROMfood_category_table
    GROUP BYfood_category
    ORDER BYitem_num DESC;
    
  • 在现有的产品明细表里重新定义一列字段,作为我们就餐人数判断的产品分类

    drop table if exists food_type;
    create table food_type as
    SELECTitem_name,price,restaurant_id,food_category,
    CASEWHEN food_category IN ( '鸡肉类', '羊肉类', '虾类', '咖喱菜', '鱼肉类', '主菜', '芝士菜' ) THEN'主菜' WHEN food_category IN ( '饼', '米饭' ) THEN'主食' WHEN food_category IN ( '饮料', '酒', '酸奶' ) THEN'饮料' WHEN food_category IN ( '酱', '腌菜' ) THEN'佐料' ELSE '小食' END AS food_type
    FROMfood_category_table;
    
  • 再来看一下重新定义过后产品的分类情况

    SELECTcount( DISTINCT item_name ) AS item_num,food_type,food_category
    FROMfood_type
    GROUP BYfood_type,food_category
    ORDER BYfood_type,food_category,item_num DESC;
    
  • 将交易明细表与我们刚定义的产品明细表进行关联,把产品分类和价格加入明细当中

    SELECTa.*,b.food_type,b.price
    FROMrestaurant_orders aJOIN food_type b ON a.`Item_Name` = b.item_name AND a.Restaurant_Id = b.restaurant_id;
    
  • 目前一行记录是一笔订单的一种产品的售卖情况,如果一笔订单有若干样产品会分成若干行,我们希望把一笔订单的详情,从多行统一到一行中,同时用我们事先定义的系数计算。

    select a.`Order_Number`,a.`Order_Date`,a.restaurant_id,round(sum(a.Quantity*b.price),2) as total_amount,
    sum(case when food_type='主食' then a.Quantity*1 else 0 end) as staple_food_count,
    sum(case when food_type='主菜' then a.Quantity*1 else 0 end) as main_course_count,
    sum(case when food_type='饮料' then a.Quantity*1 else 0 end) as drink_count,
    sum(case when food_type='小食' then a.Quantity*0.5 else 0 end) as snack_count
    from restaurant_orders a join food_type b
    on a.`Item_Name`=b.item_name and a.Restaurant_Id=b.restaurant_id
    group by a.`Order_Number`,a.`Order_Date`,a.Restaurant_Id;
    
  • 比较主食,主菜,饮料,小食中的最大者

    select c.*,GREATEST(c.staple_food_count,c.main_course_count,c.drink_count,c.snack_count) as max_count from
    (select a.`Order_Number`,a.`Order_Date`,a.restaurant_id,round(sum(a.Quantity*b.price),2) as total_amount,
    sum(case when food_type='主食' then a.Quantity*1 else 0 end) as staple_food_count,
    sum(case when food_type='主菜' then a.Quantity*1 else 0 end) as main_course_count,
    sum(case when food_type='饮料' then a.Quantity*1 else 0 end) as drink_count,
    sum(case when food_type='小食' then a.Quantity*0.5 else 0 end) as snack_count
    from restaurant_orders a join food_type b
    on a.`Item_Name`=b.item_name and a.Restaurant_Id=b.restaurant_id
    group by a.`Order_Number`,a.`Order_Date`,a.Restaurant_Id) c;
  • 最后,增加向下取整的逻辑,并且确保最小就餐人数为1

    select c.*,
    GREATEST(floor(GREATEST(c.staple_food_count,c.main_course_count,c.drink_count,c.snack_count)),1) as customer_count from
    (select a.`Order_Number`,a.`Order_Date`,a.restaurant_id,round(sum(a.Quantity*b.price),2) as total_amount,
    sum(case when food_type='主食' then a.Quantity*1 else 0 end) as staple_food_count,
    sum(case when food_type='主菜' then a.Quantity*1 else 0 end) as main_course_count,
    sum(case when food_type='饮料' then a.Quantity*1 else 0 end) as drink_count,
    sum(case when food_type='小食' then a.Quantity*0.5 else 0 end) as snack_count
    from restaurant_orders a join food_type b
    on a.`Item_Name`=b.item_name and a.Restaurant_Id=b.restaurant_id
    group by a.`Order_Number`,a.`Order_Date`,a.Restaurant_Id) c;
  • 新建一张表格,将两家店每一笔交易的时间,金额,就餐人数,主食,饮料,小食数存储进去

    DROP TABLE IF EXISTS restaurants_orders_customer_count;
    CREATE TABLE restaurants_orders_customer_count AS SELECT
    c.*, GREATEST( floor( GREATEST( c.staple_food_count, c.main_course_count, c.drink_count, c.snack_count )), 1 ) AS customer_count
    FROM(SELECTa.`Order_Number`,a.`Order_Date`,a.restaurant_id,round( sum( a.Quantity * b.price ), 2 ) AS total_amount,sum( CASE WHEN food_type = '主食' THEN a.Quantity * 1 ELSE 0 END ) AS staple_food_count,sum( CASE WHEN food_type = '主菜' THEN a.Quantity * 1 ELSE 0 END ) AS main_course_count,sum( CASE WHEN food_type = '饮料' THEN a.Quantity * 1 ELSE 0 END ) AS drink_count,sum( CASE WHEN food_type = '小食' THEN a.Quantity * 0.5 ELSE 0 END ) AS snack_count FROMrestaurant_orders aJOIN food_type b ON a.`Item_Name` = b.item_name AND a.Restaurant_Id = b.restaurant_id GROUP BYa.`Order_Number`,a.`Order_Date`,a.Restaurant_Id ) c;
  • 检查一下之前担心的饮料过多导致的推测异常占比

    SELECTcount( CASE WHEN drink_count >= 5 THEN `Order_Number` ELSE NULL END ) AS outlier_count,count(*) AS total_count,round( count( CASE WHEN drink_count >= 5 THEN `Order_Number` ELSE NULL END )/ count(*), 5 ) AS outlier_rate
    FROMrestaurants_orders_customer_count;
    outlier_count total_count outlier_rate
    13 33055 0.0004
  • 有了就餐人数之后,我们还可以进行进一步分析

    SELECTrestaurant_id,avg( customer_count ) AS avg_cc,avg( total_amount ) AS ta,avg( total_amount / customer_count ) AS avg_scc,avg( staple_food_count / customer_count ) AS avg_staple,avg( main_course_count / customer_count ) AS avg_main,avg( drink_count / customer_count ) AS avg_drink,avg( snack_count / customer_count ) AS avg_snake
    FROMrestaurants_orders_customer_count
    group by restaurant_id;

5 结果解读

  • 有了就餐人数之后,我们能够增添许多新KPI,例如人均花费,人均产品数等
  • 根据新增的就餐人数,我们可以学习每天各个时段的用餐场景。例如什么时候最有可能一人食,什么时候最有可能2人约饭,什么时候最有可能多人聚餐等。
  • 对于就餐人数比较固定的用户,我们是否可以考虑推出一些定制化的套餐或者促销产品,促进每个餐期的营业表现?

6 小结

  • 现实生活中,我们会遇到一些问题,问题的答案不能直接获取,但可以推理得到,例如:

    • 煎饼摊的老板没仔细算过每天能做多少个煎饼,但通过用了多少面粉可以推算出来
    • 突然有人问你今天是几号,你一时不记得但转念想到明天预约了植树节的亲子活动。
#mermaid-svg-RhX0wWhViVzTnwcK .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-RhX0wWhViVzTnwcK .label text{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .node rect,#mermaid-svg-RhX0wWhViVzTnwcK .node circle,#mermaid-svg-RhX0wWhViVzTnwcK .node ellipse,#mermaid-svg-RhX0wWhViVzTnwcK .node polygon,#mermaid-svg-RhX0wWhViVzTnwcK .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-RhX0wWhViVzTnwcK .node .label{text-align:center;fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .node.clickable{cursor:pointer}#mermaid-svg-RhX0wWhViVzTnwcK .arrowheadPath{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-RhX0wWhViVzTnwcK .flowchart-link{stroke:#333;fill:none}#mermaid-svg-RhX0wWhViVzTnwcK .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-RhX0wWhViVzTnwcK .edgeLabel rect{opacity:0.9}#mermaid-svg-RhX0wWhViVzTnwcK .edgeLabel span{color:#333}#mermaid-svg-RhX0wWhViVzTnwcK .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-RhX0wWhViVzTnwcK .cluster text{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-RhX0wWhViVzTnwcK .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-RhX0wWhViVzTnwcK text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-RhX0wWhViVzTnwcK .actor-line{stroke:grey}#mermaid-svg-RhX0wWhViVzTnwcK .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-RhX0wWhViVzTnwcK .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-RhX0wWhViVzTnwcK #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-RhX0wWhViVzTnwcK .sequenceNumber{fill:#fff}#mermaid-svg-RhX0wWhViVzTnwcK #sequencenumber{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK #crosshead path{fill:#333;stroke:#333}#mermaid-svg-RhX0wWhViVzTnwcK .messageText{fill:#333;stroke:#333}#mermaid-svg-RhX0wWhViVzTnwcK .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-RhX0wWhViVzTnwcK .labelText,#mermaid-svg-RhX0wWhViVzTnwcK .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-RhX0wWhViVzTnwcK .loopText,#mermaid-svg-RhX0wWhViVzTnwcK .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-RhX0wWhViVzTnwcK .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-RhX0wWhViVzTnwcK .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-RhX0wWhViVzTnwcK .noteText,#mermaid-svg-RhX0wWhViVzTnwcK .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-RhX0wWhViVzTnwcK .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-RhX0wWhViVzTnwcK .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-RhX0wWhViVzTnwcK .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-RhX0wWhViVzTnwcK .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .section{stroke:none;opacity:0.2}#mermaid-svg-RhX0wWhViVzTnwcK .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-RhX0wWhViVzTnwcK .section2{fill:#fff400}#mermaid-svg-RhX0wWhViVzTnwcK .section1,#mermaid-svg-RhX0wWhViVzTnwcK .section3{fill:#fff;opacity:0.2}#mermaid-svg-RhX0wWhViVzTnwcK .sectionTitle0{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .sectionTitle1{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .sectionTitle2{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .sectionTitle3{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-RhX0wWhViVzTnwcK .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .grid path{stroke-width:0}#mermaid-svg-RhX0wWhViVzTnwcK .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-RhX0wWhViVzTnwcK .task{stroke-width:2}#mermaid-svg-RhX0wWhViVzTnwcK .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .taskText:not([font-size]){font-size:11px}#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-RhX0wWhViVzTnwcK .task.clickable{cursor:pointer}#mermaid-svg-RhX0wWhViVzTnwcK .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-RhX0wWhViVzTnwcK .taskText0,#mermaid-svg-RhX0wWhViVzTnwcK .taskText1,#mermaid-svg-RhX0wWhViVzTnwcK .taskText2,#mermaid-svg-RhX0wWhViVzTnwcK .taskText3{fill:#fff}#mermaid-svg-RhX0wWhViVzTnwcK .task0,#mermaid-svg-RhX0wWhViVzTnwcK .task1,#mermaid-svg-RhX0wWhViVzTnwcK .task2,#mermaid-svg-RhX0wWhViVzTnwcK .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutside0,#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutside2{fill:#000}#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutside1,#mermaid-svg-RhX0wWhViVzTnwcK .taskTextOutside3{fill:#000}#mermaid-svg-RhX0wWhViVzTnwcK .active0,#mermaid-svg-RhX0wWhViVzTnwcK .active1,#mermaid-svg-RhX0wWhViVzTnwcK .active2,#mermaid-svg-RhX0wWhViVzTnwcK .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-RhX0wWhViVzTnwcK .activeText0,#mermaid-svg-RhX0wWhViVzTnwcK .activeText1,#mermaid-svg-RhX0wWhViVzTnwcK .activeText2,#mermaid-svg-RhX0wWhViVzTnwcK .activeText3{fill:#000 !important}#mermaid-svg-RhX0wWhViVzTnwcK .done0,#mermaid-svg-RhX0wWhViVzTnwcK .done1,#mermaid-svg-RhX0wWhViVzTnwcK .done2,#mermaid-svg-RhX0wWhViVzTnwcK .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-RhX0wWhViVzTnwcK .doneText0,#mermaid-svg-RhX0wWhViVzTnwcK .doneText1,#mermaid-svg-RhX0wWhViVzTnwcK .doneText2,#mermaid-svg-RhX0wWhViVzTnwcK .doneText3{fill:#000 !important}#mermaid-svg-RhX0wWhViVzTnwcK .crit0,#mermaid-svg-RhX0wWhViVzTnwcK .crit1,#mermaid-svg-RhX0wWhViVzTnwcK .crit2,#mermaid-svg-RhX0wWhViVzTnwcK .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-RhX0wWhViVzTnwcK .activeCrit0,#mermaid-svg-RhX0wWhViVzTnwcK .activeCrit1,#mermaid-svg-RhX0wWhViVzTnwcK .activeCrit2,#mermaid-svg-RhX0wWhViVzTnwcK .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-RhX0wWhViVzTnwcK .doneCrit0,#mermaid-svg-RhX0wWhViVzTnwcK .doneCrit1,#mermaid-svg-RhX0wWhViVzTnwcK .doneCrit2,#mermaid-svg-RhX0wWhViVzTnwcK .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-RhX0wWhViVzTnwcK .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-RhX0wWhViVzTnwcK .milestoneText{font-style:italic}#mermaid-svg-RhX0wWhViVzTnwcK .doneCritText0,#mermaid-svg-RhX0wWhViVzTnwcK .doneCritText1,#mermaid-svg-RhX0wWhViVzTnwcK .doneCritText2,#mermaid-svg-RhX0wWhViVzTnwcK .doneCritText3{fill:#000 !important}#mermaid-svg-RhX0wWhViVzTnwcK .activeCritText0,#mermaid-svg-RhX0wWhViVzTnwcK .activeCritText1,#mermaid-svg-RhX0wWhViVzTnwcK .activeCritText2,#mermaid-svg-RhX0wWhViVzTnwcK .activeCritText3{fill:#000 !important}#mermaid-svg-RhX0wWhViVzTnwcK .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-RhX0wWhViVzTnwcK g.classGroup text .title{font-weight:bolder}#mermaid-svg-RhX0wWhViVzTnwcK g.clickable{cursor:pointer}#mermaid-svg-RhX0wWhViVzTnwcK g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-RhX0wWhViVzTnwcK g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-RhX0wWhViVzTnwcK .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-RhX0wWhViVzTnwcK .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-RhX0wWhViVzTnwcK .dashed-line{stroke-dasharray:3}#mermaid-svg-RhX0wWhViVzTnwcK #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK .commit-id,#mermaid-svg-RhX0wWhViVzTnwcK .commit-msg,#mermaid-svg-RhX0wWhViVzTnwcK .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-RhX0wWhViVzTnwcK g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-RhX0wWhViVzTnwcK g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-RhX0wWhViVzTnwcK g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-RhX0wWhViVzTnwcK .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-RhX0wWhViVzTnwcK .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-RhX0wWhViVzTnwcK .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-RhX0wWhViVzTnwcK .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-RhX0wWhViVzTnwcK .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-RhX0wWhViVzTnwcK .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-RhX0wWhViVzTnwcK .edgeLabel text{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-RhX0wWhViVzTnwcK .node circle.state-start{fill:black;stroke:black}#mermaid-svg-RhX0wWhViVzTnwcK .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-RhX0wWhViVzTnwcK #statediagram-barbEnd{fill:#9370db}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-state .divider{stroke:#9370db}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-RhX0wWhViVzTnwcK .note-edge{stroke-dasharray:5}#mermaid-svg-RhX0wWhViVzTnwcK .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-RhX0wWhViVzTnwcK .error-icon{fill:#522}#mermaid-svg-RhX0wWhViVzTnwcK .error-text{fill:#522;stroke:#522}#mermaid-svg-RhX0wWhViVzTnwcK .edge-thickness-normal{stroke-width:2px}#mermaid-svg-RhX0wWhViVzTnwcK .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-RhX0wWhViVzTnwcK .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-RhX0wWhViVzTnwcK .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-RhX0wWhViVzTnwcK .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-RhX0wWhViVzTnwcK .marker{fill:#333}#mermaid-svg-RhX0wWhViVzTnwcK .marker.cross{stroke:#333}:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}#mermaid-svg-RhX0wWhViVzTnwcK {color: rgba(0, 0, 0, 0.75);font: ;}

数据推演
已知数据
未知数据
  • 数据推断的价值:

    • 数据本身就是资产,而获取新数据的成本不断增加,数据推断的价值愈发突出
    • 数据推断是基于已经存在的数据资产,发掘出来的“新”数据,相当于是已较低的成本增加了数据资产

多场景业务-数据推断相关推荐

  1. 多业务场景实战-数据推断

    数据推断 学习目标 知道数据推断的使用场景 使用SQL完成关键指标推断逻辑 1 业务背景:缺失关键指标 疫情期间,一家印度外卖餐厅想通过数据分析,数据挖掘提升销量,但是在历史数据中缺少了很重要的一个维 ...

  2. 思考产品架构的4个视角:业务、场景、数据/功能、实现

    我们今天以AIoT为例,来聊一聊思考产品架构的4个视角:业务.场景.数据/功能.实现 . 这篇文章的案例内容,主要来自于https://aiotframework.org/index.php?titl ...

  3. 多场景业务实战(有点多)

    数据推断 学习目标 知道数据推断的使用场景 使用SQL完成关键指标推断逻辑 1 业务背景:缺失关键指标 疫情期间,一家印度外卖餐厅想通过数据分析,数据挖掘提升销量,但是在历史数据中缺少了很重要的一个维 ...

  4. 大数据-案例-离线数仓-在线教育:MySQL(业务数据)-ETL(Sqoop)->Hive数仓【ODS层-数据清洗->DW层(DWD-统计分析->DWS)】-导出(Sqoop)->MySQL->可视化

    一.商业BI系统概述 商业智能系统,通常简称为商业智能系统,是商业智能软件的简称,是为提高企业经营绩效而采用的一系列方法.技术和软件的总和.通常被理解为将企业中的现有数据转换为知识并帮助企业做出明智的 ...

  5. Mix3D:大规模三维场景的数据增强(3DV2021)

    点击上方"3D视觉工坊",选择"星标" 干货第一时间送达 作者丨图灵智库 来源丨 泡泡机器人SLAM 标题: Mix3D: Out-of-Context Dat ...

  6. 开放下载!《阿里巴巴大数据及AI实战》深度解析典型场景大数据实践

    来源:开发者社区 本文约2000字,建议阅读5分钟. 阿里经济体大数据及AI典型场景最佳实践全揭秘.2019不容错过的大数据实战手册--<阿里巴巴大数据及AI实战>现在可以免费下载阅读啦! ...

  7. PostgreSQL 业务数据质量 实时监控 实践

    2019独角兽企业重金招聘Python工程师标准>>> 标签 PostgreSQL , pg_stat , 实时质量监控 背景 当业务系统越来越庞大后,各个业务线的数据对接会越来越频 ...

  8. 判断用户是否存在再进行新增_基于tableau从商业分析模型角度对业务数据进行多维度分析--【商业分析类】...

    基于tableau从商业分析模型角度对业务数据进行多维度分析 常规商业数据分析方法: 财务多维指标 客户生命周期 客户价值RFM 客户留存分析 购物篮关联分析 漏斗转化ABtest 以下内容主要从商业 ...

  9. 民生银行场景化数据中台是如何炼成的?

    简介:数据中台的建设是一项系统性工程,从组织架构.支撑技术到流程规范,既要有宏观的顶层设计,又要有强有力的落地执行,数据中台的建设没有一劳永逸的办法,企业需要从战略层面进行更多思考,再配合选择合适的数 ...

最新文章

  1. C#统计一段时间内有多少个星期几
  2. 海量数据的实时指标计算
  3. 【转载】单片机的背后
  4. Windows 系统如何查看本机的 IP 地址
  5. 红旗linux添加usb无线网卡,在Ubuntu 8.10中安装无线网卡RTL8187SE驱动
  6. Androidstudio查不出具体哪行报错解决办法
  7. Java泛型的个人理解
  8. 三维点云 PCA(上)
  9. 使用并解析 OPML 格式的订阅列表来转移自己的 RSS 订阅(概念篇)
  10. C++新手入门第一课
  11. HDRP shader 获取阴影(Custom Pass)
  12. API接口使用方法(封装好的电商平台)
  13. 梅科尔工作室-许博利-鸿蒙笔记2
  14. In-memory Computing with SAP HANA读书笔记 - 第二章:SAP HANA overview
  15. HTML5方方面面的活动报道,大家来吐槽啊
  16. java 解析swf_基于Java SWFTools实现把pdf转成swf
  17. ArcGIS中将线转换为面
  18. 【攻破html系列——第三天】文本标签和容器标签
  19. 记录: ATM取款机表的数据库设计思考
  20. 大厂程序员元气满满的一天!

热门文章

  1. 手机聊天APP技术开发
  2. sqliteconnection中的version一旦比先前的大,则执行onUpgrade;模仿疯狂猜图游戏;matrix设置图片比例
  3. 服务器解压文件出错,压缩包解压错误我的电脑上,所以的压缩包解压时都会出错:1:在别的 爱问知识人...
  4. 安卓手机安装Linux教程 多图
  5. 基于matlab的温度信号采集,基于matlab与单片机的动态温度监控系统的设计
  6. Linux-10-centos-shell
  7. 2022-2028全球食品和制药行业用X射线检测机行业调研及趋势分析报告
  8. [翻译]Windows 8 Developer Tools C++Builder XE3
  9. 易语言入门精品课程发布了啊
  10. MySQL学习笔记——课后练习