昆山住房和城鄉(xiāng)建設(shè)局網(wǎng)站優(yōu)化網(wǎng)站內(nèi)容
目錄
- 1、要完成的任務(wù)
- 2、認(rèn)識(shí)數(shù)據(jù)
- 3、SQL數(shù)據(jù)加工
- 4、excel形成分析儀
1、要完成的任務(wù)
目標(biāo):結(jié)合SQL和excel實(shí)現(xiàn)餐飲業(yè)日銷(xiāo)售情況分析儀,如下表:
認(rèn)識(shí)分析儀:
切片器:店面
分為四部分:KPI 、組合圖、餅圖、數(shù)據(jù)透視表
KPI指標(biāo):
- 當(dāng)天銷(xiāo)售情況
- 當(dāng)天桌子使用情況
- 當(dāng)天每把椅子的使用情況
組合圖:每小時(shí)的銷(xiāo)售額與銷(xiāo)量變化趨勢(shì)
餅圖:不同菜品下的銷(xiāo)售額占比情況,銷(xiāo)量占比情況
數(shù)據(jù)透視表:不同菜品下的銷(xiāo)售額情況,銷(xiāo)量情況
2、認(rèn)識(shí)數(shù)據(jù)
表結(jié)構(gòu)信息:
bill表中缺失金額,order表缺失店名信息 —bill表與order表連接一下可以解決
反映不同店的桌子信息:
shop表要補(bǔ)充總座位表
3、SQL數(shù)據(jù)加工
-
用orderdetail表創(chuàng)建單匯總金額表(OrderGroup)–計(jì)算每單號(hào)的總金額
以orderdetail表的billnumber單號(hào)字段為匯總依據(jù),求出每條billnumber下pay的加總值。
新表字段:billnumber(單號(hào))、pay(金額) -
用Bill表與OrderGroup表創(chuàng)建新單號(hào)詳細(xì)表(NewBill)–newbill = bill+每單總金額+每單折扣后金額
以billnumber為關(guān)鍵字段關(guān)聯(lián)兩表,將OrderGroup表中的pay字段合并到Bill表中,并使用pay與billdiscount字段計(jì)算出折扣金額。
新表字段:所有Bill表中的字段、pay(金額)、rebate(折扣金額)
計(jì)算邏輯:Rebate = pay * billdiscount -
用Shopdetail表創(chuàng)建新店面情況表(NewShopDetail)–添加每家店的總座位數(shù)
在原有shopdetail表字段基礎(chǔ)上計(jì)算并添加allseats字段
新表字段:所有ShopDetail表中的字段、allseats(總座位數(shù))
計(jì)算邏輯:allseats = twotable * 2 + three * 3 + fourtable * 6 -
用OrderDetail表與Bill表創(chuàng)建新點(diǎn)菜明細(xì)表(NewOrderDetail)–給order表增加店名信息
以billnumber為關(guān)鍵字段關(guān)聯(lián)兩表,并用Bill表中的shopname與OrderDetail表中的所有字段組成新表
新表字段:shopname(店名)、OrderDetail表中的所有字段 -
用NewBill表與NewShopDetail表創(chuàng)建店匯總信息表(ShopTotal)
以shopname字段為關(guān)鍵字段關(guān)聯(lián)兩表,并以shopname字段為匯總條件,創(chuàng)建以下字段
新表字段:
店名: b.shopname
單數(shù): b.billnumber的計(jì)數(shù)
人數(shù): b.peoplecount的加總
折扣總金額: b.rebate的加總
店匯總金額: b.pay的加總
單均消費(fèi): b.pay的合計(jì)值/b.billnumber的計(jì)數(shù)值
人均消費(fèi): b.pay的合計(jì)值/b.peoplecount的合計(jì)值
總臺(tái)數(shù): s.alltable
總座位數(shù): s.allseats
翻臺(tái)率: b.billnumber的計(jì)數(shù)值/s.alltable (總單數(shù)/總桌數(shù))
上座率: b.peoplecount的合計(jì)值/s.allseats
折扣率: b.rebate的合計(jì)值/b.pay的合計(jì)值
導(dǎo)入bill表:
create database CateringCase;use CateringCase;-- 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
);#導(dǎo)入數(shù)據(jù)
load data local infile 'D:/liwork/data/-bill.csv' into table Billfields terminated by ',';select * from Bill;
導(dǎo)入OrderDetail表:
-- OrderDetail table
create table OrderDetail(billnumber varchar(20) not null default '-',detail varchar(20) not null default '-',pay int not null default 0
);#導(dǎo)入數(shù)據(jù)
load data local infile 'D:/liwork/data/-order.csv' into table OrderDetailfields terminated by ',';select * from OrderDetail;
導(dǎo)入ShopDetail表:
-- 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
);#導(dǎo)入數(shù)據(jù)
load data local infile 'D:/liwork/data/-shop.csv' into table ShopDetailfields terminated by ',';select * from ShopDetail;
數(shù)據(jù)加工:
-- 數(shù)據(jù)加工
-- 創(chuàng)建單匯總金額表
Create table OrderGroup(select billnumber, sum(pay) as pay from OrderDetailgroup by billnumber
);select * from OrderGroup;-- 創(chuàng)建新單號(hào)詳細(xì)表
Create table NewBill(
select b.*,o.pay,b.billdiscount * o.pay as rebate from bill as b left join ordergroup as o
on b.billnumber = o.billnumber);select * from NewBill;
NewBill表:
-- 創(chuàng)建新店面情況表
create table NewShopDetail(
select *, (twotable * 2 + threetable * 3 + fourtable * 6) as allseats
from shopdetail as s);select * from NewShopDetail;
NewShopDetail表:
-- 創(chuàng)建新點(diǎn)菜明細(xì)表
create table neworderdetail(
select b.shopname,o.* from orderdetail as o left join bill as b
on o.billnumber = b.billnumber
);select * from neworderdetail;
neworderdetail表:
-- 創(chuàng)建店匯總信息表
create table ShopTotal(
select b.shopname as 店名, count(b.billnumber) as 單數(shù),
sum(b.peoplecount) as 人數(shù),sum(b.rebate) as 折扣總金額,sum(b.pay) as 店匯總金額,
sum(b.pay)/count(b.billnumber) as 單均消費(fèi),
sum(b.pay)/sum(b.peoplecount) as 人均消費(fèi),
s.alltable as 總臺(tái)數(shù),
s.allseats as 總座位數(shù),
count(b.billnumber)/s.alltable as 翻臺(tái)率,
sum(b.peoplecount)/s.allseats as 上座率,
sum(b.rebate)/sum(b.pay) as 折扣率
from newbill as b left join newshopdetail as s
on b.shopname = s.shopname
group by b.shopname);select * from shoptotal;
shoptotal表:
4、excel形成分析儀
從excel中連接MySQL,導(dǎo)入數(shù)據(jù)后做數(shù)據(jù)透視圖,不斷調(diào)整