|
|
Question : How to rewrite Case statement in Group By
|
|
Sql server handles this OK (Northwind example), but I'm passing this to another database system that does not allow it in Group By clauses.
How could this be rewritten without the select case in the Group By?
Thx
SELECT CASE WHEN c.CompanyName Like 'a%' THEN 'Begins with A' ELSE c.CompanyName END FROM Customers c GROUP BY CASE WHEN c.CompanyName Like 'a%' THEN 'Begins with A' ELSE c.CompanyName END ORDER BY CASE WHEN c.CompanyName Like 'a%' THEN 'Begins with A' ELSE c.CompanyName END
|
Answer : How to rewrite Case statement in Group By
|
|
Well when all things fails, do this
SELECT GIVEMEANAME FROM ( SELECT CASE WHEN c.CompanyName Like 'a%' THEN 'Begins with A' ELSE c.CompanyName END GIVEMEANAME FROM Customers c ) A GROUP BY GIVEMEANAME ORDER BY GIVEMEANAME ;
|
|
|
|