MySQL Forums
Forum List  »  Optimizer & Parser

Re: left join with sum and group by
Posted by: Rick James
Date: August 20, 2010 11:40PM

Give this a try... First find all the employees (SELECT DISTINCT ...). Then use a cross join to get all dates and all employees. Finally do the LEFT JOIN as you tried.

SELECT, a.weekday, a.workinghours,
       sum(b.hours) - a.workinghours
    FROM a
    JOIN ( SELECT DISTINCT employee FROM b ) AS e
    LEFT JOIN b  ON =
    GROUP BY, e.employee
(Note the missing ON clause in the JOIN)

Options: ReplyQuote

Written By
August 18, 2010 05:46AM
Re: left join with sum and group by
August 20, 2010 11:40PM
August 27, 2010 08:01PM
September 07, 2010 05:08AM

Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.