question on aws cost analyzing through athena

0

why this query is not executing ? SELECT DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS month_line_item_usage_start_date, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0 ELSE line_item_unblended_cost END) AS sum_line_item_unblended_cost, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment) WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0 WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0 WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee) WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0 ELSE line_item_unblended_cost END) AS amortized_cost, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (-savings_plan_amortized_upfront_commitment_for_billing_period) WHEN (line_item_line_item_type = 'RIFee') THEN (-reservation_amortized_upfront_fee_for_billing_period) WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN (-line_item_unblended_cost) ELSE 0 END) AS ri_sp_trueup, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN line_item_unblended_cost WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN line_item_unblended_cost ELSE 0 END) AS ri_sp_upfront_fees FROM "cudos_aggregated_cur_db"."cudos" GROUP BY 'month_line_item_usage_start_date' limit 10

getting error as SYNTAX_ERROR: line 2:4: '"date_format"(line_item_usage_start_date, '%Y-%m-%d')' must be an aggregate expression or appear in GROUP BY clause This query ran against the "cudos_aggregated_cur_db" database, unless qualified by the query. Please post the error message on our forum or contact customer support with Query Id: cfe03f00-4992-4d04-b1fc-689bb432e420

1개 답변
0

The error message is indicating that the DATE_FORMAT function is being used on the "line_item_usage_start_date" column, but it is not being included in the GROUP BY clause. The DATE_FORMAT function is used to format the date to a specific format, but it must be included in the GROUP BY clause along with the other columns that are being selected in the query.

In the GROUP BY clause, you need to include the month_line_item_usage_start_date which is the DATE_FORMAT function applied on line_item_usage_start_date.

SELECT DATE_FORMAT((line_item_usage_start_date),'%Y-%m-%d') AS month_line_item_usage_start_date, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0 ELSE line_item_unblended_cost END) AS sum_line_item_unblended_cost, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanCoveredUsage') THEN savings_plan_savings_plan_effective_cost WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (savings_plan_total_commitment_to_date - savings_plan_used_commitment) WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN 0 WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN 0 WHEN (line_item_line_item_type = 'DiscountedUsage') THEN reservation_effective_cost WHEN (line_item_line_item_type = 'RIFee') THEN (reservation_unused_amortized_upfront_fee_for_billing_period + reservation_unused_recurring_fee) WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN 0 ELSE line_item_unblended_cost END) AS amortized_cost, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanRecurringFee') THEN (-savings_plan_amortized_upfront_commitment_for_billing_period) WHEN (line_item_line_item_type = 'RIFee') THEN (-reservation_amortized_upfront_fee_for_billing_period) WHEN (line_item_line_item_type = 'SavingsPlanNegation') THEN (-line_item_unblended_cost) ELSE 0 END) AS ri_sp_trueup, SUM(CASE WHEN (line_item_line_item_type = 'SavingsPlanUpfrontFee') THEN line_item_unblended_cost WHEN ((line_item_line_item_type = 'Fee') AND (reservation_reservation_a_r_n <> '')) THEN line_item_unblended_cost ELSE 0 END) AS ri_sp_upfront_fees FROM "cudos_aggregated_cur_db"

profile picture
답변함 일 년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠