MySQL Forums
Forum List  »  Optimizer & Parser

Re: LEFT JOIN WHERE GROUP BY
Posted by: irek kordirko
Date: April 04, 2012 05:12PM

Hello Daniel,

try this query:
SELECT ifnull( cnt, 0 ) count, name
FROM (
    SELECT statusinternal_id, count(*) as cnt
    FROM support 
    WHERE ( create_date >= '2011-02-01 00:00:00' 
    AND create_date <= '2011-02-31 23:59:59' )
    GROUP BY statusinternal_id 
) as x
RIGHT JOIN support_internalstatus s
ON x.statusinternal_id = s.id
;

+-------+----------------------+
| count | name                 |
+-------+----------------------+
|     2 | Wrong item delivered |
|     3 | Exchanged            |
|     2 | Warranty expired     |
|     0 | Warranty             |
+-------+----------------------+
4 rows in set (0.00 sec)

Options: ReplyQuote


Subject
Views
Written By
Posted
2461
April 02, 2012 02:51AM
1013
April 02, 2012 12:04PM
1068
April 02, 2012 01:24PM
1108
April 02, 2012 04:29PM
1657
April 03, 2012 12:50AM
1074
April 03, 2012 05:40PM
1189
April 03, 2012 11:22PM
Re: LEFT JOIN WHERE GROUP BY
1040
April 04, 2012 05:12PM
836
April 04, 2012 11:10PM
1290
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.