title: SQL syntax to SUM field after converting from JSON and casting to float
body: <p>I have the following PostgreSQL query:</p>
  <pre><code>SELECT 
  DISTINCT ON (a.employee_id)
      a.id, a.type, a.reporting_date, a.transaction_source, a.employee, a.tags, a.start_date,
      a.data::json-&gt;&gt;'revenue' revenue,
      CAST (a.data::json-&gt;&gt;'net_revenue' AS FLOAT) net_revenue,
      a.employee_details::json-&gt;&gt;'employee_tags' employee_details
      
  FROM table_a a
  JOIN table_b b
  ON a.employee_id = b.id
  WHERE a.type IN ('Meta::Sales',  'Meta::Expenses')
  AND (b.start_date AT TIME ZONE 'UTC' AT TIME ZONE 'EST')::date BETWEEN '2022-01-01' AND '2022-01-31'
  AND ((b.state = 'AVAILABLE') OR (b.state= 'UNAVAILABLE'))
  ORDER BY
      a.employee_id
  </code></pre>
  <p>I would like to sum <code>net_revenue</code> in the following line:</p>
  <pre><code>CAST (a.data::json-&gt;&gt;'net_revenue' AS FLOAT) net_revenue,
  </code></pre>
  <p>I tried to wrap the line above in a <code>SUM()</code>, as follows:</p>
  <pre><code>SUM(CAST (a.data::json-&gt;&gt;'net_revenue' AS FLOAT) net_revenue)
  </code></pre>
  <p>But, this fails with the syntax error.</p>
  <p>What is the syntax to do this?</p>
  <p>Thanks!</p>