Mini数据仓库搭建学习:家庭日常购物支出
目的:学习数据仓库
(以下内容 仅是个人对学习数据仓库的一种尝试
是很肤浅的
希望大家看了以后能给以指导
后续我会在这个基础上进一步学习)
步骤:
1.建立数据库 数据表 填充数据
2.建立数据仓库数据库 数据源 维度 多维数据集
3.运行MDX
============================
1.建立数据库 数据表 填充数据
============================
---- 创建家庭表
CREATE TABLE [familyList] (
[familyList_ID] [int] IDENTITY (1, 1) NOT NULL ,
[family_ID] [int] NOT NULL ,
[cy_ID] [int] NOT NULL ,
[cy_Name] [char] (20) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
---- 创建超市表
CREATE TABLE [superMarket] (
[superM_ID] [int] IDENTITY (1, 1) NOT NULL ,
[superM_Name] [char] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[superM_Address] [char] (30) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
---- 创建日期时间表
CREATE TABLE [dateList] (
[date_ID] [int] IDENTITY (1, 1) NOT NULL ,
[the_date] [datetime] NOT NULL ,
[the_month] [int] NOT NULL ,
[the_quertar] [int] NOT NULL ,
[the_year] [int] NOT NULL
) ON [PRIMARY]
GO
---- 创建购物表
CREATE TABLE [payList] (
[payList_id] [int] IDENTITY (1, 1) NOT NULL ,
[payerID] [int] NOT NULL ,
[payDate] [int] NOT NULL ,
[paySuperM] [int] NOT NULL ,
[payPrice] [money] NOT NULL ,
[payNote] [char] (20) COLLATE Chinese_PRC_CI_AS NOT NULL
) ON [PRIMARY]
GO
/*
---- 家庭成员表
INSERT INTO familyList
SELECT '1','1','张三'
UNION SELECT '1','2','张三妻'
UNION SELECT '1','3','张三子'
UNION SELECT '1','4','张三女'
UNION SELECT '2','1','李四'
UNION SELECT '2','2','李四妻'
UNION SELECT '2','3','李四父'
UNION SELECT '2','4','李四母'
UNION SELECT '3','1','王五'
UNION SELECT '3','2','王五妻'
SELECT * FROM familyList
*/
/*
---- 购物超市表
DECLARE @i int
SET @i = 1
WHILE @i < 11
BEGIN
INSERT INTO superMarket (superM_Name,superM_Address)
VALUES( '超市'+Convert(char,@i) ,'超市地址'+Convert(char,@i) )
SET @i=(@i+1)
END
SELECT * FROM superMarket
*/
/*
---- 时间日期表
DECLARE @currDate datetime
SET @currDate = Convert(datetime,'2006/09/01')
WHILE @currDate< Convert(datetime,'2006/11/01')
BEGIN
INSERT INTO dateList
VALUES(@currDate,
datename (month,@currDate),
datename (quarter,@currDate),
datename (year,@currDate))
SET @currDate = dateadd(day,1,@currDate)
END
SELECT * FROM dateList
*/
/*
---- 日常购物记录表
DECLARE @i int,@randID int
SET @i = 1
WHILE @i < 62 --每天都有消费
BEGIN
SET @randID = @i%10
INSERT INTO payList(payerID,payDate,paySuperM,payPrice,payNote)
VALUES(@randID,@i,@randID,CEILING(100 * rand(@i)),'购物'+Convert(char,@i))
SET @i = (@i + 1);
END
SELECT * FROM payList
ORDER BY payList_id ASC
*/
===========================================
2.建立数据仓库数据库 数据源 维度 多维数据集
===========================================
数据源:
事实表
payList (payerID,payDate,payAdd,payprice)
维度表
时间表dateList(date_id,the_date,the_month,the_quertar,the_year)
购物超市表superMarket(id,superMarketName,address)
家庭成员表familyList(id,family_id,cy_id,cy_name)
多维数据集
payList
=========
3.运行MDX
=========
各季度 每个家庭 的 总购物 支出
select
{[dateList].[季度].members } on columns,
{[familyList].[Family Id].members } on rows
from
payList
各季度 每个家庭成员 的 总购物 支出
select
{[dateList].[季度].members } on columns,
{[familyList].[Family List Id].members } on rows
from
payList
第1个家庭 各成员各季度 总购物支出
select
{[familyList].[所有 familyList].[1] } on columns,
{[dateList].[月].members } on rows
from payList
各超市 各月 收入
select
{[superMList].[Super M Id].members } on columns,
{[dateList].[月].members } on rows
from payList
posted on 2006-12-25 17:52 freeliver54 阅读(1151) 评论(2) 编辑 收藏 举报