以hive的角度检查语法: with cur_dim_comb as (SELECT DISTINCT t.dim_comb ,t.var_sub_class ,t.acc_value FROM gerp.cux_cst_data_alloc_his t WHERE t.top_var_type = '10' AND t.job_ver_id in (SELECT ver.job_ver_id AS p_job_ver_id FROM gerp.cux_cst_dist_jobs_all job INNER JOIN gerp.cux_cst_dist_jobs_vers_all ver ON job.job_id = ver.job_id )) select tp.bd_code --事业部编码 ,tp.bd_name --事业部名称 ,hp.ou_code --OU名称 ,hp.ou_name --OU编码 ,op.main_class_desc --差异大类 ,op.acc_value --科目代码 ,op.acc_desc --科目名称 ,op.dim_comb --区分维度 ,op.begin_amount --期初余额 ,op.accrual_amount --本期发生 ,op.balance_diff_alloc_amount --期末差异结存 ,op.var_sub_class ,op.main_class_value ,op.org_id ,op.period_name ,op.job_ver_id from (select up.* ,q1.* from (SELECT DISTINCT maincl.* ,t.* FROM t inner join (SELECT fv.flex_value ,fv.description FROM fv inner join fs on fv.flex_value_set_id = fs.flex_value_set_id AND fs.flex_value_set_name = 'CUX_CST_VARIANCE_TYPE' AND fv.enabled_flag = 'Y' AND fv.hierarchy_level = '2' AND fv.flex_value LIKE '10%' ) maincl on t.var_main_class = maincl.flex_value inner join cur_dim_comb on cur_dim_comb.var_sub_class = t.var_sub_class and cur_dim_comb.acc_value = t.acc_value WHERE 1 = 1 AND t.top_var_type = '10' AND t.job_ver_id in (SELECT ver.job_ver_id AS p_job_ver_id FROM gerp.cux_cst_dist_jobs_all job INNER JOIN gerp.cux_cst_dist_jobs_vers_all ver ON job.job_id = ver.job_id) ORDER BY maincl.description ,t.acc_value ,cur_dim_comb.dim_comb ) up inner join (SELECT t1.* ,SUM(t1.begin_amount) begin_amount ,SUM(t1.accrual_amount) accrual_amount ,SUM(t1.balance_diff_alloc_amount) balance_diff_alloc_amount FROM gerp.cux_cst_data_alloc_his t1 LEFT JOIN gerp.cux_cst_data_alloc_his t ON t1.top_var_type = '10' AND t1.var_sub_class = t.var_sub_class --p_var_sub_class AND t1.org_id = t.org_id --p_org_id AND t1.period_name = t.period_name --p_period_name AND t1.job_ver_id = t.job_ver_id --p_job_ver_id AND t1.acc_value = t.acc_value --p_acc_value WHERE t1.dim_comb in (select distinct dim_comb from cur_dim_comb) group by t1.org_id,t1.period_name,t1.job_ver_id,t1.var_sub_class,t1.acc_value ) q1 on q1.org_id = up.org_id --p_org_id AND q1.period_name = up.period_name --p_period_name AND q1.job_ver_id = up.job_ver_id --p_job_ver_id AND q1.var_sub_class = up.var_sub_class --p_var_sub_class AND q1.acc_value = up.acc_value --p_acc_value ) op
时间: 2023-08-10 20:02:13 浏览: 198
从 Hive 的角度来检查语法,以下是您提供的 SQL 查询语句:
```
with cur_dim_comb as (
SELECT DISTINCT t.dim_comb, t.var_sub_class, t.acc_value
FROM gerp.cux_cst_data_alloc_his t
WHERE t.top_var_type = '10'
AND t.job_ver_id in (
SELECT ver.job_ver_id AS p_job_ver_id
FROM gerp.cux_cst_dist_jobs_all job
INNER JOIN gerp.cux_cst_dist_jobs_vers_all ver
ON job.job_id = ver.job_id
)
)
select
tp.bd_code, --事业部编码
tp.bd_name, --事业部名称
hp.ou_code, --OU名称
hp.ou_name, --OU编码
op.main_class_desc, --差异大类
op.acc_value, --科目代码
op.acc_desc, --科目名称
op.dim_comb, --区分维度
op.begin_amount, --期初余额
op.accrual_amount, --本期发生
op.balance_diff_alloc_amount, --期末差异结存
op.var_sub_class,
op.main_class_value,
op.org_id,
op.period_name,
op.job_ver_id
from (
select up.*, q1.*
from (
SELECT DISTINCT
maincl.*,
t.*
FROM
t
inner join (
SELECT
fv.flex_value,
fv.description
FROM
fv
inner join fs
on fv.flex_value_set_id = fs.flex_value_set_id
AND fs.flex_value_set_name = 'CUX_CST_VARIANCE_TYPE'
AND fv.enabled_flag = 'Y'
AND fv.hierarchy_level = '2'
AND fv.flex_value LIKE '10%'
) maincl
on t.var_main_class = maincl.flex_value
inner join cur_dim_comb
on cur_dim_comb.var_sub_class = t.var_sub_class
and cur_dim_comb.acc_value = t.acc_value
WHERE
1 = 1
AND t.top_var_type = '10'
AND t.job_ver_id in (
SELECT ver.job_ver_id AS p_job_ver_id
FROM gerp.cux_cst_dist_jobs_all job
INNER JOIN gerp.cux_cst_dist_jobs_vers_all ver
ON job.job_id = ver.job_id
)
ORDER BY
maincl.description,
t.acc_value,
cur_dim_comb.dim_comb
) up
inner join (
SELECT
t1.*,
SUM(t1.begin_amount) begin_amount,
SUM(t1.accrual_amount) accrual_amount,
SUM(t1.balance_diff_alloc_amount) balance_diff_alloc_amount
FROM
gerp.cux_cst_data_alloc_his t1
LEFT JOIN gerp.cux_cst_data_alloc_his t
ON t1.top_var_type = '10'
AND t1.var_sub_class = t.var_sub_class --p_var_sub_class
AND t1.org_id = t.org_id --p_org_id
AND t1.period_name = t.period_name --p_period_name
AND t1.job_ver_id = t.job_ver_id --p_job_ver_id
AND t1.acc_value = t.acc_value --p_acc_value
WHERE
t1.dim_comb in (select distinct dim_comb from cur_dim_comb)
group by
t1.org_id,
t1.period_name,
t1.job_ver_id,
t1.var_sub_class,
t1.acc_value
) q1
on q1.org_id = up.org_id --p_org_id
AND q1.period_name = up.period_name --p_period_name
AND q1.job_ver_id = up.job_ver_id --p_job_ver_id
AND q1.var_sub_class = up.var_sub_class --p_var_sub_class
AND q1.acc_value = up.acc_value --p_acc_value
) op
```
从语法角度来看,该查询语句是有效的。但是,如果您想要确保语句完全符合您的预期,请先测试该语句在您的环境中的执行结果。
阅读全文