数据立方体如图所示:
在数据立方体上的操作有:切片、切块、旋转、上卷和下钻。
在数据立方体的某一维度上选定一个维成员的操作叫切片,而对两个或多个维执行选择则叫做切块。下图逻辑上展示了切片和切块操作:
这两种操作的 SQL 模拟语句如下,主要是对 WHERE 语句做工作。
旋转就是指改变报表或页面的展示方向。对于使用者来说,就是个视图操作,而从 SQL 模拟语句的角度来说,就是改变 SELECT 后面字段的顺序而已。下图逻辑上展示了旋转操作:
上卷可以理解为”无视”某些维度;下钻则是指将某些维度进行细分。下图逻辑上展示了上卷和下钻操作:
这两种操作的 SQL 模拟语句如下,主要是对 GROUP BY 语句做工作。
此数据是从SQL Server2012版本数据库导出,仅供借鉴与参考
/****** Object: Table [dbo].[analysisTable] Script Date: 2019/3/11 15:33:52 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[analysisTable](
[timeID] [tinyint] NOT NULL,
[productID] [tinyint] NOT NULL,
[areaID] [tinyint] NOT NULL,
[number] [int] NOT NULL,
[money] [int] NOT NULL ) ON [PRIMARY] GO
CREATE TABLE [dbo].[areaTable](
[areaID] [tinyint] IDENTITY(1,1) NOT NULL,
[areaCou] [varchar](200) NOT NULL,
[areaPro] [varchar](50) NOT NULL,
[areaCity] [varchar](50) NOT NULL,
[areaDoor] [varchar](200) NOT NULL,
CONSTRAINT [PK_areaTable] PRIMARY KEY CLUSTERED
(
[areaID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[productTable](
[productID] [tinyint] IDENTITY(1,1) NOT NULL,
[productType] [nvarchar](50) NOT NULL,
[productName] [nvarchar](50) NOT NULL,
CONSTRAINT [PK_productTable] PRIMARY KEY CLUSTERED
(
[productID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
CREATE TABLE [dbo].[timeTable](
[timeID] [tinyint] IDENTITY(1,1) NOT NULL,
[timeYear] [varchar](50) NOT NULL,
[timeMonth] [varchar](50) NOT NULL,
CONSTRAINT [PK_timeTable] PRIMARY KEY CLUSTERED
(
[timeID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
select timeTable.timeMonth, productTable.productName, areaTable.areaDoor
from analysisTable, timeTable, productTable, areaTable
where
analysisTable.timeID = timeTable.timeID AND
analysisTable.productID = productTable.productID AND
analysisTable.areaID = areaTable.areaID AND
analysisTable.productID = 1;
本文链接:https://cloud.tencent.com/developer/article/1558188
本文采用CC BY-NC-SA 3.0 Unported协议进行许可,转载请保留此文章链接