title: postgres query writing to find from my tables which guy exceeded the planned working hour
body: <ol>
  <li>employee</li>
  <li>emplog
  The diagram will show a brief</li>
  </ol>
  <p><img src="https://i.stack.imgur.com/an5ja.png" alt="1" /></p>
  <p>I want to find the which employee exceeded the planned working hours which  is represented in employee table by defined_working_hours (TIME).
  I have written this query</p>
  <pre><code>  SELECT em.empid,  em.entrytime, em.exittime, em.break, e.firstname, e.lastname,e.defined_working_hours, SUM(em.exittime - em.entrytime)  AS workedhours, date_part('month',em.entrytime) FROM emplog AS em JOIN employee AS e ON e.empid = em.empid WHERE workedhours &gt; defined_working_hours GROUP BY em.empid, e.defined_working_hours, em.entrytime, em.exittime, em.break, e.firstname, e.lastname, e.empid, date_part('month',em.entrytime) ORDER BY e.empid;
  </code></pre>
  <p>But I am getting a error Column &quot;workedhours &quot; does not exist.</p>
  <p>I but i know column does not exist when i run the query without &quot;
  <code>WHERE workedhours &gt; defined_working_hours</code>&quot;</p>
  <pre><code>SELECT
      em.empid,
      em.entrytime,
      em.exittime,
      em.break,
      e.firstname,
      e.lastname,
      e.defined_working_hours,
      SUM(em.exittime - em.entrytime) AS workedhours,
      date_part('month', em.entrytime)
  FROM emplog AS em
  JOIN employee AS e ON e.empid = em.empid
  GROUP BY
      em.empid,
      e.defined_working_hours,
      em.entrytime,
      em.exittime,
      em.break,
      e.firstname,
      e.lastname,
      e.empid,
      date_part('month', em.entrytime)
  ORDER BY e.empid;
  </code></pre>
  <p>I am getting a table but the purpose is to find which employee have exceeds their planned working hours more than 1 times per week.
  CAN SOME SHED SOME LIGHT WHERE I AM GOING WRONG.</p>