一、关于本次案列的概述
本次案列的数据是来自某餐饮数据的日销售情况,基于已经提供的数据,需要在excel中做一个各个店面的分析仪,其KPI 指标相关如下:
该问题的难点还是在于表之间的逻辑关系,以及相关业务知识。
数据表一共有三张,包括:bill order shop
他们的表结构如下:
而我们的目的是获得不同店面的数据情况,上面的三张表是不能满足这样情况的,所以我选择先在MySQL中进行数据加工,再用Excel中利用power pivot生成数据透视表和数据透视图,
当然还有其他一些操作,整体动态图的展现等。
二 、数据预处理 —基于MySQL5.7 +workbench 6.3
(1)建表与数据导入
在MySQL中先建立 库 MySQL_powerBI
create database mysql_powerbi; use mysql_powerbi; -- Bill table create table Bill( billdate date not null, billnumber varchar(20) not null default '-', shopname varchar(20) not null default '-', billdiscount float not null default 0, paytime time not null, tablenumber int not null default 0, peoplecount int not null default 0 ); #导入数据 load data local infile 'D:/mysql_powerBI/data/-bill.csv' into table Bill fields terminated by ','; select * from Bill;
表 Bill 的情况如下图,一共有 682 行
-- OrderDetail table create table OrderDetail( billnumber varchar(20) not null default '-', detail varchar(20) not null default '-', pay int not null default 0 ); #导入数据 load data local infile 'D:/mysql_powerBI/data/-order.csv' into table OrderDetail fields terminated by ','; select * from OrderDetail;
表 OrderDetail 共有 3410 行,如下:
-- ShopDetail table create table ShopDetail( ShopName varchar(20) not null default '-', twotable int not null default 0, threetable int not null default 0, fourtable int not null default 0, alltable int not null default 0 ); #导入数据 load data local infile 'D:/mysql_powerBI/data/-shop.csv' into table ShopDetail fields terminated by ','; select * from ShopDetail;
表 ShopDetail 共有 5 行,如下:
在确保上面的步骤无误后,接下来进入数据加工阶段,得到我们想要的数据