Answer the question
In order to leave comments, you need to log in
SQL GROUP BY on a column that we declared using CASE in SELECT - is it really necessary to repeat the code from SELECT?
Hello!
I read the article:
www.sql-tutorial.ru/ru/book_case_group_by_clause.html
And here, in order to group by the column that we declared using CASE in SELECT, the code from SELECT is copied. Is it possible to write somehow without copying the code? GROUP BY Type throws an error.
Here is the code from the article, if anything:
SELECT
CASE
WHEN ram < 64
THEN 'W95'
WHEN ram < 128
THEN 'W98'
ELSE 'W2k'
END Type,
COUNT(*) Qty
FROM PC
GROUP BY
CASE
WHEN ram < 64
THEN 'W95'
WHEN ram < 128
THEN 'W98'
ELSE 'W2k'
END;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question