MySQL Forums
Forum List  »  Optimizer & Parser

Re: LEFT JOIN WHERE GROUP BY
Posted by: Daniel Flöijer
Date: April 03, 2012 12:50AM

Thanks, but it still doesn't work when I add the WHERE statement. Ie like this:

SELECT sum( case when s.statusinternal_id is null then 0 else 1 end ) count, name
FROM support s
RIGHT JOIN support_internalstatus si
ON si.id = s.statusinternal_id
WHERE create_date >= '2011-02-21 00:00:00'
AND create_date <= '2011-02-31 23:59:59'
GROUP BY si.id

I then get this:

+-------+----------------------+
| count | name |
+-------+----------------------+
| 2 | Warranty |
| 4 | Wrong item delivered |
| 4 | Exchanged |
+-------+----------------------+

Instead of this:

+-------+----------------------+
| count | name |
+-------+----------------------+
| 2 | Warranty |
| 4 | Wrong item delivered |
| 4 | Exchanged |
| 0 | Warranty expired |
+-------+----------------------+

Options: ReplyQuote


Subject
Views
Written By
Posted
2978
April 02, 2012 02:51AM
1263
April 02, 2012 12:04PM
1292
April 02, 2012 01:24PM
1316
April 02, 2012 04:29PM
Re: LEFT JOIN WHERE GROUP BY
1980
April 03, 2012 12:50AM
1311
April 03, 2012 05:40PM
1408
April 03, 2012 11:22PM
1247
April 04, 2012 05:12PM
1015
April 04, 2012 11:10PM
1528
April 05, 2012 08:01PM


Sorry, you can't reply to this topic. It has been closed.

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.