# 创建历史与当前临时表 CREATE TEMPORARY TABLE history (SELECT line_item_product_code AS product, SUM(line_item_unblended_cost) AS cost FROM `athena`.`2021-05` GROUPBY product ORDERBY cost DESC); CREATE TEMPORARY TABLEcurrent (SELECT line_item_product_code AS product, SUM(line_item_unblended_cost) AS cost FROM `athena`.`2022-05` GROUPBY product ORDERBY cost DESC);
# 合并计算临时表全连接 CREATE TEMPORARY TABLE left_join (SELECT history.product, history.cost AS history, current.cost AScurrent FROM history LEFTJOINcurrentON history.product = current.product);
CREATE TEMPORARY TABLE right_join(SELECT current.product, history.cost AS history, current.cost AScurrent FROM history RIGHTJOINcurrentON history.product = current.product); # 展示结果 SELECT* FROM left_join UNION SELECT* FROM right_join;
SELECT'MD4X'AS project, (SELECTSUM(line_item_unblended_cost) AS cost FROM split.`2022-05-jtbb-szhzx-sjglb` WHERE line_item_usage_account_id ='************' AND Region ='cn-north-1') - (SELECTSUM(line_item_unblended_cost) AS cost FROM split.`2022-05-jtbb-szhzx-sjglb` WHERE line_item_usage_account_id ='************' AND Region ='cn-north-1' AND resource_tags_user_project REGEXP 'kns|catalog') AS cost ;
SELECTSUM(line_item_unblended_cost) FROM split.`2022-05-jtbb-szhzx-sjglb` WHERE line_item_usage_account_id ='************' AND Region ='cn-north-1' AND ( resource_tags_user_project NOT REGEXP 'kns|catalog' OR resource_tags_user_project ISNULL);