diff --git a/cid/builtin/core/data/queries/trends/daily_anomaly_detection.sql b/cid/builtin/core/data/queries/trends/daily_anomaly_detection.sql index 795872780..12cc18ae9 100644 --- a/cid/builtin/core/data/queries/trends/daily_anomaly_detection.sql +++ b/cid/builtin/core/data/queries/trends/daily_anomaly_detection.sql @@ -8,6 +8,6 @@ SELECT , "round"("sum"("line_item_usage_amount"), 2) "line_item_usage_amount" FROM ("${cur2_database}"."${cur2_table_name}" -LEFT JOIN aws_accounts ON ("line_item_usage_account_id" = "account_id")) +LEFT JOIN account_map ON ("line_item_usage_account_id" = "account_id")) WHERE ("date_diff"('day', "date"("line_item_usage_start_date"), "date"("now"())) <= 110) GROUP BY "line_item_usage_start_date", "line_item_usage_account_id", "account_name", 4 \ No newline at end of file diff --git a/cid/builtin/core/data/queries/trends/monthly_anomaly_detection.sql b/cid/builtin/core/data/queries/trends/monthly_anomaly_detection.sql index d115ef78e..7a922c418 100644 --- a/cid/builtin/core/data/queries/trends/monthly_anomaly_detection.sql +++ b/cid/builtin/core/data/queries/trends/monthly_anomaly_detection.sql @@ -11,6 +11,6 @@ SELECT , "round"("sum"("line_item_usage_amount"), 2) "line_item_usage_amount" FROM ("${cur2_database}"."${cur2_table_name}" -LEFT JOIN aws_accounts ON ("line_item_usage_account_id" = "account_id")) +LEFT JOIN account_map ON ("line_item_usage_account_id" = "account_id")) WHERE ("date_diff"('month', "date"("bill_billing_period_start_date"), "date"("now"())) <= 20) -GROUP BY "bill_billing_period_start_date", "line_item_usage_account_id", "account_name", 4 \ No newline at end of file +GROUP BY "bill_billing_period_start_date", "line_item_usage_account_id", "account_name", 4 \ No newline at end of file diff --git a/cid/builtin/core/data/queries/trends/monthly_bill_by_account.sql b/cid/builtin/core/data/queries/trends/monthly_bill_by_account.sql index 6500c0f3b..2ad48a1b3 100644 --- a/cid/builtin/core/data/queries/trends/monthly_bill_by_account.sql +++ b/cid/builtin/core/data/queries/trends/monthly_bill_by_account.sql @@ -19,15 +19,10 @@ WITH SELECT "account_name" , "account_id" + , "parent_account_name" "payer_account_name" + , "parent_account_id" FROM - aws_accounts -) -, t3 AS ( - SELECT - "payer_account_name" - , "account_id" - FROM - payer_account_name_map + account_map ) , t4 AS ( SELECT @@ -47,13 +42,12 @@ WITH SELECT t1.* , "t2"."account_name" -, "t3"."payer_account_name" -, TRY_CAST("t4"."region_latitude" AS decimal) "region_latitude" -, TRY_CAST("t4"."region_longitude" AS decimal) "region_longitude" -, (CASE WHEN (("t5"."aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NOT NULL)) THEN "t1"."product_product_name" WHEN (("aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NULL)) THEN 'Other' ELSE "t5"."aws_service_category" END) "aws_service_category" +, "t2"."payer_account_name" +, TRY_CAST("t3"."region_latitude" AS decimal) "region_latitude" +, TRY_CAST("t3"."region_longitude" AS decimal) "region_longitude" +, (CASE WHEN (("t4"."aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NOT NULL)) THEN "t1"."product_product_name" WHEN (("aws_service_category" IS NULL) AND ("t1"."product_product_name" IS NULL)) THEN 'Other' ELSE "t4"."aws_service_category" END) "aws_service_category" FROM - ((((t1 -LEFT JOIN t2 ON ("t1"."line_item_usage_account_id" = "t2"."account_id")) -LEFT JOIN t3 ON ("t1"."bill_payer_account_id" = "t3"."account_id")) -LEFT JOIN t4 ON ("t1"."product_region" = "t4"."region_name")) -LEFT JOIN t5 ON ("t1"."line_item_product_code" = "t5"."line_item_product_code")) \ No newline at end of file + (((t1 +LEFT JOIN t2 ON ("t1"."line_item_usage_account_id" = "t2"."account_id" AND "t1"."bill_payer_account_id" = "t2"."parent_account_id")) +LEFT JOIN t3 ON ("t1"."product_region" = "t3"."region_name")) +LEFT JOIN t4 ON ("t1"."line_item_product_code" = "t4"."line_item_product_code")) \ No newline at end of file