Open hotsun1508 opened 2 months ago
Very interesting.
SELECT
CASE
WHEN age BETWEEN 0 AND 9 THEN '0-9'
WHEN age BETWEEN 10 AND 19 THEN '10-19'
WHEN age BETWEEN 20 AND 29 THEN '20-29'
ELSE '30+'
END AS age_group
FROM ?
--GROUP BY age_group
Gives the expected result (see https://jsfiddle.net/bpkesrh2/ ) and if I want to group across the case column it returns "30+" (see https://jsfiddle.net/1jLnxdmz/1/ ) like you have uncovered.
BUT!!!
If I remove any values over 30 (see https://jsfiddle.net/1jLnxdmz/2/ ) it STILL returns 30+
when adding the group by
back in (see https://jsfiddle.net/1jLnxdmz/3/ )
This indicate that the group by
logic somehow fetches the value in theELSE
clause - no matter the content actually selected.
Hi, I'm expecting different results when executing the query below. There seems to be an issue with data extraction. (I've checked that there's no problem with CASE WHEN usage: https://github.com/AlaSQL/alasql/wiki/CASE)
The data type of the age column is numeric, and the expected result when extracting this data is as follows.
FYI, I've got this result by executing the same query in PostgreSQL.
The query isn't returning the expected results when I run it. Could you help me out? Thank you so much! 😊