MySQL Forums
Forum List  »  General

Re: GROUP BY and NULL values
Posted by: Peter Brawley
Date: June 10, 2020 03:43PM

You can avoid Nulls with ...
     CASE
      	WHEN null then ''
        when `oo`.`name` LIKE 'Color%' THEN `oo`.`value` 
      	ELSE ''
      END AS `Option`,
That gives this dataset from the inner query ...

+----------+-----+-------------+-------+----------+
| Order ID | Qty | Option      | Style | Product  |
+----------+-----+-------------+-------+----------+
|    12345 |   1 | Classic Red | C     | ProductA |
|    12345 |   1 | Classic Red | C     | ProductA |
|    12345 |   1 | Classic Red | V     | ProductA |
|    12345 |   1 | Classic Red | V     | ProductA |
|    12346 |   1 | Grey        |       | ProductB |
|    12346 |   1 |             | Y     | ProductB |
+----------+-----+-------------+-------+----------+

But I don't understand what you expect from the pattern ...select a,max(b)...group by a,b. Grouping by the only non-aggregated value, order_id, gets ...

+----------+------+-------------+-------+----------+
| Order ID | Qty  | Option      | Style | Product  |
+----------+------+-------------+-------+----------+
|    12345 |    1 | Classic Red | V     | ProductA |
|    12346 |    1 | Grey        | Y     | ProductB |
+----------+------+-------------+-------+----------+

Options: ReplyQuote


Subject
Written By
Posted
June 10, 2020 12:50PM
Re: GROUP BY and NULL values
June 10, 2020 03:43PM


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.