PostgreSQL how to compare a column's numeric value against the SUM of another numeric value?
<p>I am new to PostgreSQL and restored this Database in order to practice my Queries. It contains the following Tables:</p>

<p><a href="https://i.stack.imgur.com/9RSJ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9RSJ2.png" alt="enter image description here"></a></p>

<p>What is the best query to find how many orders have an order_total that is less than the sum of their line_total(s)?</p>

<p>This is the query I have but I doubt that my number is accurate. I feel like I am doing something wrong:</p>

<pre><code>select COUNT(order_total) from orders
join order_lines
on orders.id = order_lines.order_id
having count(order_total) &lt; sum(line_total)
</code></pre>

<p>Am I querying correctly or not?</p>

<p>Thanks</p>

<ul>
<li>Pill</li>
</ul>