<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to Determine the Cost for Each Query Run Against SQL Warehouse Serverless? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/133484#M49860</link>
    <description>&lt;P&gt;Can you Share the query that you used ?&lt;/P&gt;</description>
    <pubDate>Wed, 01 Oct 2025 17:21:20 GMT</pubDate>
    <dc:creator>skumarraj</dc:creator>
    <dc:date>2025-10-01T17:21:20Z</dc:date>
    <item>
      <title>How to Determine the Cost for Each Query Run Against SQL Warehouse Serverless?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/84442#M37195</link>
      <description>&lt;P&gt;Hello Everyone.&lt;/P&gt;&lt;P&gt;First of all, I would like to thank you to databricks to enable system tables for customers. It does help a lot.&amp;nbsp;I am working on cost optimization topic. Particularly sql warehouse serverless. I am not sure all of you have tried system tables. my question is&lt;/P&gt;&lt;P&gt;is it possible to find out cost per query (Sql Warehouse Serverless) using system tables?&lt;BR /&gt;&lt;BR /&gt;I have started writing query combining system tables. unfortunately it is not giving expected results.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 16:01:49 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/84442#M37195</guid>
      <dc:creator>VIRALKUMAR</dc:creator>
      <dc:date>2024-08-27T16:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out cost for each query run against (sql warehouse serverless) ?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/84457#M37198</link>
      <description>&lt;P&gt;Hey VIRALKUMAR,&lt;/P&gt;
&lt;P&gt;I recommend using the &lt;A href="https://docs.databricks.com/en/admin/system-tables/billing.html" target="_self"&gt;billing usage system table&lt;/A&gt; to find total DBUs by SKU (SQL) and the &lt;A href="https://docs.databricks.com/en/admin/system-tables/pricing.html" target="_self"&gt;pricing system table&lt;/A&gt; to find the appropriate price. You can use the sample queries in those pages to get started.&lt;/P&gt;
&lt;P&gt;Hope that's helpful!&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 16:01:08 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/84457#M37198</guid>
      <dc:creator>katefray</dc:creator>
      <dc:date>2024-08-27T16:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to find out cost for each query run against (sql warehouse serverless) ?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/84481#M37199</link>
      <description>&lt;P&gt;Hi Katefray&lt;/P&gt;&lt;P&gt;Thank you for the reply and documentation links. I have already tried with billing usage system table (&lt;STRONG&gt;&lt;EM&gt;system.billing.usage&lt;/EM&gt;&lt;/STRONG&gt;) and pricing system table (&lt;STRONG&gt;&lt;EM&gt;&lt;SPAN&gt;system&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;billing&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;list_prices&lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;) but unfortunately billing usage table doesn't have direct reference to&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;system.query.&lt;/EM&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&lt;EM&gt;&lt;STRONG&gt;history&lt;/STRONG&gt;. S&lt;/EM&gt;o we can't join them and get the DBU usage and calculate the query cost.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Here is sample query. &lt;EM&gt;(It is not giving expected result)&amp;nbsp;&lt;BR /&gt;&lt;/EM&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;SELECT  q.workspace_id,
        q.compute.warehouse_id,
        q.compute.type,
        q.read_files,
        q.read_rows,
        q.statement_text,
        q.statement_type,
        q.total_task_duration_ms,
        b.usage_date,
        b.usage_unit,
        b.usage_quantity,
        b.sku_name,
        (b.usage_quantity * l.pricing.default) AS total_cost,
        q.executed_by
FROM system.query.history q
JOIN system.billing.usage b
  ON q.compute.warehouse_id = b.usage_metadata.warehouse_id
  AND q.workspace_id = b.workspace_id
JOIN system.billing.list_prices l
  ON l.sku_name = b.sku_name
WHERE q.workspace_id = "xxxxxxxxxxxx "
  AND b.usage_date &amp;gt;= (current_date() - INTERVAL '1' DAY)
  AND l.price_end_time IS NULL&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VIRALKUMAR_0-1724776377452.png" style="width: 809px;"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/10647i63C83D024C39575F/image-dimensions/809x108/is-moderation-mode/true?v=v2" width="809" height="108" role="button" title="VIRALKUMAR_0-1724776377452.png" alt="VIRALKUMAR_0-1724776377452.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here is an example&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;1. Statement Type is SHOW. It took 0 milli seconds. the usage is showing 1.09 DBU, cost per DBU is 0.95 and total cost is 1.03 It doesn't make sense &lt;EM&gt;&lt;STRONG&gt;show&lt;/STRONG&gt;&amp;nbsp;sql&amp;nbsp;&lt;/EM&gt;statement is costing $1.03.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Aug 2024 16:51:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/84481#M37199</guid>
      <dc:creator>VIRALKUMAR</dc:creator>
      <dc:date>2024-08-27T16:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to Determine the Cost for Each Query Run Against SQL Warehouse Serverless?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/122096#M46649</link>
      <description>&lt;P&gt;Yes, it does not make sense to see that high cost per query, please note that the below table contains hourly spend, so you cant get query wise usage.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;system.billing.usage&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 07:54:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/122096#M46649</guid>
      <dc:creator>sanjeevktm</dc:creator>
      <dc:date>2025-06-18T07:54:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to Determine the Cost for Each Query Run Against SQL Warehouse Serverless?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/122100#M46651</link>
      <description>&lt;P&gt;Yes, You are absolutely right. If you don't want to consider ideal time of databricks Sql warehouse. You can apply filter to remove ideal time of Databricks Sql warehouse and consider only query execution time and multiply with cost_per_minutes, Ideal time of Sql warehouse you can consider into another Category.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jun 2025 08:10:58 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/122100#M46651</guid>
      <dc:creator>VIRALKUMAR</dc:creator>
      <dc:date>2025-06-18T08:10:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to Determine the Cost for Each Query Run Against SQL Warehouse Serverless?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/133484#M49860</link>
      <description>&lt;P&gt;Can you Share the query that you used ?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Oct 2025 17:21:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-determine-the-cost-for-each-query-run-against-sql/m-p/133484#M49860</guid>
      <dc:creator>skumarraj</dc:creator>
      <dc:date>2025-10-01T17:21:20Z</dc:date>
    </item>
  </channel>
</rss>

