S
S
sorry_i_noob2018-02-09 00:17:24
SQL
sorry_i_noob, 2018-02-09 00:17:24

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

1 answer(s)
L
Lazy @BojackHorseman, 2018-02-09
@sorry_i_noob

need to be repeated

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question