[数据库]数据科学OLAP实验


实验要求

本实验是一个简单的数据仓库模型,事实表保存销售记录,维表保存用户、时间、产品、销售人员、商店等信息,这些维表具有维度的层次结构。比如时间维度的年、月、日等。

在这个数据仓库上,我们可以运行数据仓库分析查询,获得一些汇总结果,帮助我们对业务有所了解,以便安排后续的商业活动。

本实例的目的是让读者对关系数据库、OLAP、事实表、维表、维度层次结构等,有进一步的认识。


实验过程

模型

销售表为事实表,周围有5个维表,分别表示销售人员、产品、客户,也就是谁把什么卖给了谁。还有日期、和商店,也就是什么时间,在哪个地方。

日期维度,具有年、季度、月、日层次结构。

商店维度,具有国家、省份、城市层次结构。

产品维度,具有产品大类、产品层次结构。

在这里插入图片描述


建表

(以下使用Navicat作为数据库前端可视化。)

Dim_saleperson 的建表 sql 语句如下。

create table dim_saleperson (
	saleperson_id char(18) primary key not null, 
	name char(16), 
	gender char(1), 
	birth_day char(8)
);

Dim_product 的建表 sql 语句如下。

create table dim_product (
	product_id char(18) primary key not null, 
	name char(16), 
	category char(1),  -- F 表示视频,D 表示日用品
	price numeric(16,3)
);

Dim_customer 的建表 sql 语句如下。

create table dim_customer (
	customer_id char(18) primary key not null, 
	name char(16), 
	gender char(1), 
	birth_day char(8)
);

Dim_date 的建表 sql 语句如下。

create table dim_date (
	date_id char(18) primary key not null, 
	date char(8), 
	day integer, 
	month integer, 
	quarter integer, 
	year integer
);

Dim_store 的建表 sql 语句如下。

create table dim_store (
	store_id char(18) primary key not null, 
	name char(16), 
	city char(16), 
	province char(16), 
	country char(16)
);

Fact_sales 的建表 sql 语句如下。

create table fact_sales (
	Date_id char(18) primary key not null,
	Saleperson_id char(18),
	Store_id char(18),
	Customer_id char(18),
	Product_id char(18), 
	price numeric(16.3), 
	quantity integer,
	amount numeric(16,3)
);

注入数据

  • Dim_saleperson 的 insert 语句如下。

4 个销售人员:
S001, 王涛
S002, 李刚
S003, 张莉
S004, 王雪

insert into dim_saleperson values('s001', 'wang tao', 'M', '19990303'); 
insert into dim_saleperson values('s002', 'li gang', 'M', '19980303')
  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值