Athena 高仿Cost Explorer账单SQL模板

spider · · 25 次点击 · 开始浏览    置顶
未验证, ``` WITH cost_data AS ( SELECT line_item_usage_account_id AS account_id, product_product_name AS service_name, product_region AS region, line_item_resource_id AS resource_id, -- 处理不同类型的成本 CASE WHEN line_item_line_item_type IN ('SavingsPlanCoveredUsage', 'SavingsPlanNegation') THEN savings_plan_effective_cost WHEN line_item_line_item_type IN ('DiscountedUsage') THEN reservation_effective_cost WHEN line_item_line_item_type IN ('Usage') THEN line_item_unblended_cost WHEN line_item_line_item_type IN ('RIFee') THEN reservation_amortized_upfront_fee_for_billing_period + reservation_recurring_fee_for_usage WHEN line_item_line_item_type IN ('SavingsPlanRecurringFee') THEN savings_plan_recurring_commitment_for_billing_period WHEN line_item_line_item_type IN ('Credit', 'Refund') THEN line_item_unblended_cost -- Credits通常为负数 ELSE 0 END AS effective_cost FROM your_cur2_table_name WHERE line_item_usage_start_date BETWEEN TIMESTAMP '2025-04-01' AND TIMESTAMP '2025-04-30' ) SELECT account_id, service_name, region, resource_id, SUM(effective_cost) AS total_effective_cost FROM cost_data GROUP BY account_id, service_name, region, resource_id ORDER BY total_effective_cost DESC; ```

关注本站微信公众号(和以上内容无关)InfraPub ,扫码关注:InfraPub

25 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传