Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The WHERE filter may be wrong. Note that first datetime in the condition starts at '08:00:00' -</p> <pre><code>SELECT FROM_UNIXTIME('1346475600') dt1, FROM_UNIXTIME('1348290000') dt2; +---------------------+---------------------+ | dt1 | dt2 | +---------------------+---------------------+ | 2012-09-01 08:00:00 | 2012-09-22 08:00:00 | +---------------------+---------------------+ </code></pre> <p>The type of <code>ActualEffort</code>.<code>logdate</code> field is DATE; the value '2012-09-01' is less then '2012-09-01 08:00:00'. So change this condition or use DATE function -</p> <pre><code>WHERE E.logdate BETWEEN DATE(FROM_UNIXTIME('1346475600')) AND DATE(FROM_UNIXTIME('1348290000')) </code></pre> <hr> <p><strong>(edited)</strong></p> <p>For one thing, when you join <code>StaffAssign</code> and <code>ActualEffort</code> on the <code>Tid</code> column only, you get a mini-<a href="http://en.wikipedia.org/wiki/Cartesian_product" rel="nofollow" title="Cartesian product (Wikipedia)">Cartesian product</a> for <code>Tid=123</code> in particular, because both tables contain more than one row with that <code>Tid</code> and there's no other specific condition to establish a 1:1 or, at most, 1:N relationship between the rows.</p> <p>But in fact, 1:N wouldn't do either: although it wouldn't give you the Cartesian product effect, it would result in duplicated values on one side and, as a consequence, in a distorted SUM.</p> <p>Therefore, data in <code>StaffAssign</code> and those in <code>ActualEffort</code> must be aggregated separately, <em>then</em> joined, something like this:</p> <pre><code>SELECT pl.ProjectId, pn.name, sa.Planned, ae.ActualEffort FROM ProjectList pl JOIN ProjectName pn ON pn.Id = pl.ProjectId LEFT JOIN (SELECT Tid, SEC_TO_TIME(SUM(TIME_TO_SEC(Planned))) Planned FROM StaffAssign GROUP BY Tid) sa ON sa.Tid = pl.Tid LEFT JOIN (SELECT Tid, SEC_TO_TIME(SUM(TIME_TO_SEC(ActualEffort))) ActualEffort FROM ActualEffort GROUP BY Tid) ae ON ae.Tid = pl.Tid GROUP BY ProjectId; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload