尝试在Athena SQL中执行此操作。我有“75”作为默认税类型,我需要将其替换为“76”,占税金额的20%
正在尝试在Athena SQL中执行此操作。我有“75”作为默认税类型,我需要将其替换为“76”,占税金额的20% 电流输出原样尝试在Athena SQL中执行此操作。我有“75”作为默认税类型,我需要将其替换为“76”,占税金额的20%,sql,amazon-web-services,amazon-athena,divide,percentile,Sql,Amazon Web Services,Amazon Athena,Divide,Percentile,正在尝试在Athena SQL中执行此操作。我有“75”作为默认税类型,我需要将其替换为“76”,占税金额的20% 电流输出原样 geocode tax_type tax_amt 32 75 10 32 75 15 32 75 20 32 75 18 32 75 20 32 75 17 我需要输出为 geocode tax
geocode tax_type tax_amt
32 75 10
32 75 15
32 75 20
32 75 18
32 75 20
32 75 17
我需要输出为
geocode tax_type tax_amt
32 75 10
32 75 15
32 75 20
32 75 18
32 76 20
32 75 17
SQL
帮助您变得容易:。请简化您的问题和示例代码,以突出显示您提出的特定问题,并删除其他内容。另外,请提供运行查询的示例输入数据。
SELECT CASE when d.tax_auth = '1' THEN substring(b.geocode,1,2) || '0000000'
WHEN d.tax_auth = '2' THEN substring(b.geocode,1,5) || '0000' ELSE b.geocode END AS GEOCODE,
b.JUR_NAME as JURIS_NAME,
CAST(COUNT(a.tax_amt)/COUNT(*)*100 AS DECIMAL(30,2)) AS PERCENTILE,
CASE WHEN substring(b.geocode,1,2) = '32' AND d.tax_type = '75'
THEN
CASE
WHEN CAST(COUNT(a.tax_amt)/COUNT(*)*100 AS DECIMAL(30,2)) = 0.20
THEN REPLACE (d.tax_type,'75','76')
END
ELSE
CASE
WHEN CAST(COUNT(a.tax_amt)/COUNT(*)*100 AS DECIMAL(30,2)) = 0.80
THEN d.tax_type
END
END AS TAX_TYPE,
CAST (d.tax_rate AS DECIMAL (30,5)) AS TAX_RATE,
SUM(CAST(a.tax_amt as DECIMAL(30,2))) AS TAX,
substring(b.geocode,1,2) AS STATE_GEO,
'PPD Boost Usage' AS ID,
d.tax_auth AS TAX_AUTH,
f.auth_name AS AUTH_NAME,
CASE WHEN substring(b.geocode,1,2) = '72' THEN '417' ELSE '317' END AS BU,
c.tax_descrp AS TAX_DESCRP,
CASE WHEN b.geocode like '%-%-%' THEN b.geocode ELSE substring(geocode,1,2) || '-' || substring(geocode,3,3) || '-' || substring(geocode,6,4) END AS GEOMASK,
'NO' AS COST_RECOVERY_IDENTIFIER,
CONCAT(substring(b.geocode,1,2),d.tax_auth,d.tax_type) as GL_CROSS_REF,
substring(load_id,1,6) AS YYYYMM,
c.gl_account AS GL_ACCOUNT,
d.tax_srv_type
FROM (select * from "dl_wireless_boost"."ngpp_tax_fact" where dt = (select max(dt) from "dl_wireless_boost"."ngpp_tax_fact")) a
LEFT JOIN
(SELECT g.geocode_id, g.geocode, coalesce(sq_actual_names.actual_name, g.jurisdiction_name) as JUR_NAME
FROM "dl_wireless_boost"."ngpp_geocode_dim" g `enter code here`
LEFT JOIN
(SELECT replace(geocode,'-','') as stripped_geocode, max(jurisdiction_name) as actual_name
FROM "dl_wireless_boost"."ngpp_geocode_dim"
WHERE 1=1 AND dt = (select max(dt) from "dl_wireless_boost"."ngpp_geocode_dim")
AND (geocode = geocode OR geocode = substring(geocode,1,2) || '-' || substring(geocode,3,3) || '-' || substring(geocode,6,4))
AND jurisdiction_name <> 'U'
GROUP BY 1) sq_actual_names
on g.geocode = sq_actual_names.stripped_geocode
WHERE 1=1 AND g.dt = (select max(dt) from "dl_wireless_boost"."ngpp_geocode_dim")
AND (geocode = geocode OR geocode = substring(geocode,1,2) || '-' || substring(geocode,3,3) || '-' || substring(geocode,6,4))) b
ON a.geocode_id = b.geocode_id
LEFT JOIN (select * from "dl_wireless_boost"."ngpp_tax_code_dim" where dt = (select max(dt) from "dl_wireless_boost"."ngpp_tax_code_dim")) d
ON a.tax_code_id = d.tax_code_id
LEFT JOIN "sbx_accntnganalytics"."tax_auth_name" f
ON d.tax_auth = f.tax_auth
LEFT JOIN "sbx_accntnganalytics"."tax_gl_desc" c
ON d.tax_type = c.tax_type AND substring(b.geocode,1,2) = c.state_geo
GROUP BY 1,2,4,5,7,8,9,10,11,12,13,14,15,16,17,18