Re: Interesting query outcomes
Jerry Stuckle <[email protected]> Wed, 19 Aug 2020 16:15:24 -0400
| Newsgroups | comp.databases.mysql |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On 8/18/2020 4:33 PM, Joe wrote: > I have a MySQL table field sometimes with NULL or empty values when there is no data. When I wrote the following to count data in this field: > > select CASE WHEN (TNAM is NULL || TNAM='') THEN 'default' > ELSE TNAM END, count(1) > from ITEMS group by 1; > > I got: > > | default | 2929 | > | default | 139 | > | item A | 347 | > | item B | 831 | > .... > -- why "default" repeats? I humble one is from "TNAM is NULL" and the other from "TNAM=''", and also thought they should have been combined with "group" function... Thoughts without actually update table to turn "empty" to NULL or vise versa? > > Joe > My quest would be the GROUP BY clause is being applied before the CASE WHEN clause. -- ================== Remove the "x" from my email address Jerry Stuckle [email protected] ==================