sql语法错误,信息: DataType varchar is not supported.(line 55, pos 22) == SQL == WITH gb_data as ( -- 内存条标签,拿到GB select main_ida.text_field_ooil5pe9 as item_no, main_ida.text_field_2lnermdr as qty from ods_ida_t_app0896034115789864961_m1192517514695749632 main_ida where main_ida.id = (select max(ida.id) from ods_ida_t_app0896034115789864961_m1192517514695749632 ida where ida.text_field_ooil5pe9 = main_ida.text_field_ooil5pe9) ), ck_data as ( -- 历史出库单价(元/条) SELECT item_no, '历史出库单价(元/条)' as data_type, SUBSTR(year_month, 1, 4) as cal_year, year_month as cal_date, avg_monthly_price/monthly_outbound_qty as qty FROM ( SELECT t1.item_no, t1.outbound_year_month AS year_month, SUM(CAST(t1.outbound_qty AS DOUBLE)) AS monthly_outbound_qty, ROUND(AVG(CAST(t1.actual_price_rmb AS DOUBLE)), 2) AS avg_monthly_price_usd FROM dm_server_code_level_common_data t0 left join edw_sup_pur_pva_cost_reduction_outbound_d t1 on t0.item_no = t1.item_no WHERE t1.outbound_year_month >= '202309' group by t1.item_no, t1.outbound_year_month UNION ALL SELECT q.item_no, q.year_month, q.monthly_outbound_qty, ROUND(t.outstock_price, 2) AS avg_monthly_price_usd FROM ( SELECT TRIM(t1.item_no) AS item_no, SUBSTR(CAST(t1.post_date AS STRING), 1, 6) AS year_month, SUM(CAST(t1.qty AS DOUBLE)) AS monthly_outbound_qty FROM dm_server_code_level_common_data t0 left join dm_plan_edw_sup_inv_material_out_store t1 on t0.item_no = t1.item_no WHERE SUBSTR(CAST(t1.post_date AS STRING), 1, 6) < '202309' and t1.item_no IS NOT NULL and TRIM(t1.item_no) <> '' and t0.cllb1 = "DIMM" GROUP BY TRIM(t1.item_no), SUBSTR(CAST(t1.post_date AS STRING), 1, 6) ) q JOIN ( SELECT inventory_item_code, SUBSTR(CAST(p_date AS STRING), 1, 6) AS year_month, SUM(outstock_money) / NULLIF(SUM(outstock_qty), 0) AS outstock_price FROM edw_sup_mfg_material_transactions WHERE SUBSTR(CAST(p_date AS STRING), 1, 6) < '202309' GROUP BY inventory_item_code, SUBSTR(CAST(p_date AS STRING), 1, 6) ) t ON q.item_no = t.inventory_item_code AND q.year_month = t.year_month ) combined_data ORDER BY item_no, year_month ), c_data as ( -- 汇率 select TRIM(t1.item_no) AS item_no, '汇率' as data_type, CAST(t2.year AS VARCHAR) AS cal_year, ----------------------^^^ CONCAT ( CAST(t2.year AS VARCHAR), LPAD (CAST(t2.month AS VARCHAR), 2, '0') ) AS cal_date, min( CASE WHEN ( CASE WHEN t2.orig_currency = 'CNY' THEN 1 ELSE t2.exchange_rate end ) <> 1 and t2.source_type = 'InStorage' THEN CAST( ( CASE WHEN t2.orig_currency = 'CNY' THEN 1 ELSE t2.exchange_rate end ) AS DOUBLE ) ELSE NULL END ) AS qty FROM dm_server_code_level_common_data t0 left join ods_srm_pu_acceptance_item t1 ON t1.item_no = t0.item_no left JOIN ods_srm_pu_acceptance t2 ON t1.acpt_id = t2.id AND t2.dr = 0 AND t2.latest = 1 where t1.item_no IS NOT NULL and TRIM(t1.item_no) <> '' and t0.cllb1 = "DIMM" GROUP BY TRIM(t1.item_no), CAST(t2.year AS VARCHAR), CONCAT( CAST(t2.year AS VARCHAR), LPAD(CAST(t2.month AS VARCHAR), 2, '0') ) ), a_data as ( -- 历史进料条,先拿出内存条数据,再增加年份,拿数量 select item_no, '历史进料条' as data_type, SUBSTR(cal_date, 1, 4) as cal_year, cal_date, qty from dm_server_bing2509_lishijl where cal_date is not null and class1 = 'DIMM' ), a1_data as ( -- 历史进料GB select a_data.item_no, '历史进料BG' as data_type, SUBSTR(a_data.cal_date, 1, 4) as cal_year, a_data.cal_date, (a_data.qty*gb_data.qty) as qty from a_data left join gb_data on gb_data.item_no = a_data.item_no ), e_data as ( -- 历史进料单价RMB(元/条) select TRIM(t1.item_no) AS item_no, '历史进料单价RMB(元/条)' as data_type, CAST(t2.year AS VARCHAR) AS cal_year, CONCAT ( CAST(t2.year AS VARCHAR), LPAD (CAST(t2.month AS VARCHAR), 2, '0') ) AS cal_date, round(SUM(CASE WHEN is_red_main = '0' AND has_red = '0' THEN CAST(acpt_qty AS DOUBLE) * CAST(acpt_std_price AS DOUBLE) ELSE 0 END) / NULLIF( SUM(CASE WHEN is_red_main = '0' AND has_red = '0' THEN CAST(acpt_qty AS DOUBLE) ELSE 0 END), 0) / NULLIF( MIN(CASE WHEN exchange_rate <> 1 AND source_type='InStorage' THEN CAST(exchange_rate AS DOUBLE) ELSE NULL END), 0),2) AS qty FROM dm_server_code_level_common_data t0 left join ods_srm_pu_acceptance_item t1 ON t1.item_no = t0.item_no left JOIN ods_srm_pu_acceptance t2 ON t1.acpt_id = t2.id AND t2.dr = 0 AND t2.latest = 1 where t1.item_no IS NOT NULL and TRIM(t1.item_no) <> '' and t0.cllb1 = "DIMM" GROUP BY TRIM(t1.item_no), CAST(t2.year AS VARCHAR), CONCAT( CAST(t2.year AS VARCHAR), LPAD(CAST(t2.month AS VARCHAR), 2, '0') ) ), a2_data as ( -- 历史进料金额 select ls.item_no, '历史进料金额' as data_type, SUBSTR(ls.cal_date, 1, 4) as cal_year, ls.cal_date, ed.qty*ls.qty from dm_server_bing2509_lishijl ls left join e_data ed on ed.item_no = ls.item_no and ed.cal_date = ls.cal_date where ls.cal_date is not null and ed.cal_date is not null and ls.class1 = 'DIMM' ), a3_data as ( -- 历史进料单价(元/GB) select ls.item_no, '历史进料单价(元/GB)' as data_type, SUBSTR(ls.cal_date, 1, 4) as cal_year, ls.cal_date, (ed.qty*ls.qty)/gb.qty from dm_server_bing2509_lishijl ls left join e_data ed on ed.item_no = ls.item_no and ed.cal_date = ls.cal_date left join gb_data gb on ls.item_no = gb.item_no where ls.cal_date is not null and ed.cal_date is not null and ls.class1 = 'DIMM' ), a4_data as ( -- 历史进料单价(USD/GB) select ls.item_no, '历史进料单价(USD/GB)' as data_type, ls.cal_year, ls.cal_date, ls.qty/ed.qty from a3_data ls left join c_data ed on ed.item_no = ls.item_no and ed.cal_date = ls.cal_date where ls.cal_date is not null and ed.cal_date is not null ), a5_data as ( -- 历史进料单价(USD/条) select ls.item_no, '历史进料单价(USD/条)' as data_type, ls.cal_year, ls.cal_date, ls.qty/ed.qty from e_data ls left join c_data ed on ed.item_no = ls.item_no and ed.cal_date = ls.cal_date where ls.cal_date is not null and ed.cal_date is not null ), b_data as ( -- 历史出库条 select item_no, '历史出库条' as data_type, SUBSTR(cal_date, 1, 4) as cal_year, cal_date, qty from dm_server_bing2509_lishick where cal_date is not null and class1 = 'DIMM' ), b1_data as ( -- 历史出库BG select b_data.item_no, '历史出库BG' as data_type, SUBSTR(b_data.cal_date, 1, 4) as cal_year, b_data.cal_date, (b_data.qty*gb_data.qty) as qty from b_data left join gb_data on gb_data.item_no = a_data.item_no ), b3_data as ( -- 历史出库单价(元/GB) select ls.item_no, '历史进料单价(元/GB)' as data_type, SUBSTR(ls.cal_date, 1, 4) as cal_year, ls.cal_date, (ed.qty*ls.qty)/gb.qty from dm_server_bing2509_lishick ls left join ck_data ed on ed.item_no = ls.item_no and ed.cal_date = ls.cal_date left join gb_data gb on ls.item_no = gb.item_no where ls.cal_date is not null and ed.cal_date is not null and ls.class1 = 'DIMM' ), b4_data as ( -- 历史出库单价(USD/GB) select ls.item_no, '历史出库单价(USD/GB)' as data_type, SUBSTR(ls.cal_date, 1, 4) as cal_year, ls.cal_date, ls.qty/cd.qty from b3_data ls left join c_data cd on cd.item_no = ls.item_no and cd.cal_date = ls.cal_date where ls.cal_date is not null and cd.cal_date is not null ), b5_data as ( -- 历史出库单价(USD/条) select ls.item_no, '历史出库单价(USD/条)' as data_type, ls.cal_year, ls.cal_date, ls.qty/ed.qty from ck_data ls left join c_data ed on ed.item_no = ls.item_no and ed.cal_date = ls.cal_date where ls.cal_date is not null and ed.cal_date is not null ), b6_data as ( -- 历史出库金额 select ls.item_no, '历史出库金额' as data_type, SUBSTR(ls.cal_date, 1, 4) as cal_year, ls.cal_date, ed.qty*ls.qty from b_data ls left join b3_data ed on ed.item_no = ls.item_no and ed.cal_date = ls.cal_date where ls.cal_date is not null and ed.cal_date is not null ), main_data as ( select * from c_data --汇率 UNION select * from a_data --历史进料条 UNION select * from a1_data --历史进料GB UNION select * from a2_data --历史进料金额 UNION select * from a3_data --历史进料单价元/GB UNION select * from e_data --历史进料单价元/条 UNION select * from a4_data --历史进料单价USD/GB UNION select * from a5_data --历史进料单价USD/条 UNION select * from b_data --历史出库条 UNION select * from b1_data --历史出库gb UNION select * from b6_data --历史出库金额 UNION select * from ck_data --历史出库单价元/条 UNION select * from b3_data --历史出库单价元/GB UNION select * from b4_data --历史出库单价usd/GB UNION select * from b5_data --历史出库单价USD/条 ) INSERT OVERWRITE TABLE dm_server_price_stock_202512 select nct.item_no, '' as item_name, nct.class1, nct.class2, nct.item_bm as bm, '' as jixing, nct.kehu, nct.is_china, nct.is_zte, nct.item_pp, main.data_type, main.cal_year, main.cal_date, main.qty, 0 as num_other1, 0 as num_other2, 0 as num_other3, 0 as num_other4, '' as num_other1, '' as num_other2, '' as num_other3, '' as num_other4, '' as edw_create_date, '' as edw_last_update, '' as edw_data_source, '' as valid_flag from dm_sever_label_nct nct left join main_data main on main.item_no = nct.item_no
最新发布