1.在数据存储上面,大家都是使用数据库进行存储,里面建一些表,存储数据。
场景:
一些非常复杂的计算,在存储过程里面实现,一些临时数据可以存储到临时表里面,最后将汇总的数据存储的正式表里面。
写具有业务的存储过程,一般使用变量存储临时数据,但是如果有大量数据,临时表可以结局这个问题
SQL里面的 Selelct into可以解决大量的数据插入
create,drop基于表的操作在临时表进行创建于删除。
例子:
数据交换平台:
导入数据时,将原始数据先导入临时表。
再对临时表里面的数据按照规则进行校验,成功之后进入正式库。
BI系统:
对主题分析的数据进行多维建模之后,创建临时表,汇总数据,创建临时表,存储汇总的数据。
基本BI里面的临时表,基本可以达到上千以上的临时表。
BI里面之所以能够进行多维分析,本质就是他存储了一套元数据。
指标:
建立指标字典:---作为维度再次进行多维分析
建立指标数据库:---指标设置取值公式,对其分析的数据作为源数据,再次分析
也就是所谓的切块或者切片个人的理解。
==============================================
分享一下项目里面的临时SQL
多维分析基于RDBMS进行,通过界面操作动态生成如下SQL(设计到一点小算法就是SQL的拼接,........,大家自己琢磨去......)
通过主题,对指标进行纬度分析
CREATE TABLE temp_DIM_24
(
DIM_24_fint_year VARCHAR(4000),
DIM_24_fint_month VARCHAR(4000),
DIM_24_dept_code VARCHAR(4000),
DIM_24_comp_code VARCHAR(4000),
DIM_24_prime_cost NUMBER(16, 6)
);
CREATE TABLE temp_DIM_22
(
DIM_24_fint_year VARCHAR(4000),
DIM_24_fint_month VARCHAR(4000),
DIM_24_dept_code VARCHAR(4000),
DIM_24_comp_code VARCHAR(4000),
DIM_22_dept_name VARCHAR(4000),
DIM_22_dept_code VARCHAR(4000),
DIM_24_prime_cost NUMBER(16, 6)
);
CREATE TABLE temp_DIM_21
(
DIM_24_fint_year VARCHAR(4000),
DIM_24_fint_month VARCHAR(4000),
DIM_24_dept_code VARCHAR(4000),
DIM_24_comp_code VARCHAR(4000),
DIM_22_dept_name VARCHAR(4000),
DIM_22_dept_code VARCHAR(4000),
DIM_21_comp_name VARCHAR(4000),
DIM_21_comp_code VARCHAR(4000),
DIM_24_prime_cost NUMBER(16, 6)
);
INSERT INTO temp_DIM_24
SELECT DIM_24.fint_year AS DIM_24_fint_year,
DIM_24.fint_month AS DIM_24_fint_month,
DIM_24.dept_code AS DIM_24_dept_code,
DIM_24.comp_code AS DIM_24_comp_code,
AVG(DIM_24.prime_cost) AS DIM_24_prime_cost
FROM (
SELECT *
FROM CS_DEPT_ST_DEPT_COST CS_DEPT_ST_DEPT_COST
) DIM_24
WHERE DIM_24.fint_year = '2014'
AND DIM_24.fint_month = '09'
GROUP BY
DIM_24.fint_year,
DIM_24.fint_month,
DIM_24.dept_code,
DIM_24.comp_code;
INSERT INTO temp_DIM_22
SELECT DIM_24.DIM_24_fint_year AS DIM_24_fint_year,
DIM_24.DIM_24_fint_month AS DIM_24_fint_month,
DIM_24.DIM_24_dept_code AS DIM_24_dept_code,
DIM_24.DIM_24_comp_code AS DIM_24_comp_code,
DIM_22.dept_name AS DIM_22_dept_name,
DIM_22.dept_code AS DIM_22_dept_code,
AVG(DIM_24.DIM_24_prime_cost) AS DIM_24_prime_cost
FROM temp_DIM_24 DIM_24
INNER JOIN (
SELECT *
FROM DEPT_DICT_ACCT_DEPT DEPT_DICT_ACCT_DEPT
) DIM_22
ON (1 = 1 AND DIM_22.dept_code = DIM_24.DIM_24_dept_code)
GROUP BY
DIM_24.DIM_24_fint_year,
DIM_24.DIM_24_fint_month,
DIM_24.DIM_24_dept_code,
DIM_24.DIM_24_comp_code,
DIM_22.dept_name,
DIM_22.dept_code;
INSERT INTO temp_DIM_21
SELECT DIM_22.DIM_24_fint_year AS DIM_24_fint_year,
DIM_22.DIM_24_fint_month AS DIM_24_fint_month,
DIM_22.DIM_24_dept_code AS DIM_24_dept_code,
DIM_22.DIM_24_comp_code AS DIM_24_comp_code,
DIM_22.DIM_22_dept_name AS DIM_22_dept_name,
DIM_22.DIM_22_dept_code AS DIM_22_dept_code,
DIM_21.comp_name AS DIM_21_comp_name,
DIM_21.comp_code AS DIM_21_comp_code,
AVG(DIM_22.DIM_24_prime_cost) AS DIM_24_prime_cost
FROM temp_DIM_22 DIM_22
INNER JOIN (
SELECT *
FROM SYS_COMPANY SYS_COMPANY
) DIM_21
ON (1 = 1 AND DIM_21.comp_code = DIM_22.DIM_24_comp_code)
GROUP BY
DIM_22.DIM_24_fint_year,
DIM_22.DIM_24_fint_month,
DIM_22.DIM_24_dept_code,
DIM_22.DIM_24_comp_code,
DIM_22.DIM_22_dept_name,
DIM_22.DIM_22_dept_code,
DIM_21.comp_name,
DIM_21.comp_code;
SELECT DIM_21.DIM_22_dept_code AS DIM_22_CODE,
MAX(DIM_21.DIM_22_dept_name) AS DIM_22_DISPLAY,
DIM_21.DIM_21_comp_code AS DIM_21_CODE,
MAX(DIM_21.DIM_21_comp_name) AS DIM_21_DISPLAY,
'201409' AS DIM_DATE_CODE,
'YEAR_MONTH' AS DIM_DATE_LEVEL,
AVG(DIM_21.DIM_24_prime_cost) AS DIM_24_DATA
FROM temp_DIM_21 DIM_21
GROUP BY
DIM_21.DIM_22_dept_code,
DIM_21.DIM_21_comp_code
ORDER BY
DIM_21.DIM_22_dept_code ASC,
DIM_21.DIM_21_comp_code ASC;DROP TABLE temp_DIM_24;DROP TABLE temp_DIM_22;
DROP TABLE temp_DIM_21;
上面这个SQL就是根据多维分析模型,用户选择分析维度以及指标生成临时表的数据,最后将数据插入到临时表里面
--查询SQL
SELECT DIM_22_CODE AS DIM_22_CODE,
MAX(DIM_22_DISPLAY) AS DIM_22_DISPLAY,
DIM_21_CODE AS DIM_21_CODE,
MAX(DIM_21_DISPLAY) AS DIM_21_DISPLAY,
DIM_DATE_CODE AS DIM_DATE_LAST_CODE,
AVG(DIM_24_DATA) AS DIM_24_DATA
FROM vhbi.rep_temp_report_17
WHERE DIM_DATE_CODE IN ('201409')
AND DIM_DATE_LEVEL = 'YEAR_MONTH'
AND DIM_22_CODE IN ('001', '002')
GROUP BY
DIM_22_CODE,
DIM_21_CODE,
DIM_DATE_CODE
ORDER BY
DIM_22_CODE ASC,
DIM_21_CODE ASC