shaun thornburgh <mailto:[EMAIL PROTECTED]> wrote:

> Unfortunately that doesnt work, I need to LEFT JOIN Bookings to Weeks
> but keep the current join on Projects there as well, any ideas?

Sorry, Shaun. I misunderstood what you were trying to accomplish first.

How about something along these lines (have no way of testing):

SELECT W.Number AS WEEK, WEEK(Booking_Start_Date) AS MYWEEK,
SUM(IF(B.Project_ID = "23", 1,0)) AS `Project A`,
SUM(IF(B.Project_ID = "42", 1,0)) AS `Project B`
FROM Week W, Bookings B 
INNER JOIN Projects P USING (Project_ID)
WHERE B.Booking_Type = "Booking"
AND DATE_FORMAT(B.Booking_Start_Date, "%Y-%m-%d") >= '2005-01-01'
AND DATE_FORMAT(B.Booking_Start_Date, "%Y-%m-%d") <= '2005-12-31'
HAVING WEEK = MYWEEK
GROUP BY WEEK;

Supposing you have 53 records in week with numbers ranging from 1 through
53.

Peter Normann


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to