title: SQL - nonexisting column
body: <p>I'm using POSTGRESQL database:</p>
  <p><img src="https://www.postgresqltutorial.com/postgresql-sample-database/" alt="database" /></p>
  <p>and I need to return customer's first name, last name and sum of hours they kept a film above certain limit, say 10. I wrote such query:</p>
  <pre><code>SELECT customer.first_name AS first_name, customer.last_name AS last_name,
         DATE_PART('day', rental.return_date - rental.rental_date)*24 + DATE_PART('hour', return_date - rental_date) AS sum
  FROM rental JOIN
       customer
       ON rental.customer_id = customer.customer_id
  GROUP BY sum, first_name, last_name
  HAVING MIN(sum) &gt; 10;
  </code></pre>
  <p>But it says there is no column such as sum. How can I overcome this issue?</p>