Skip to content
Advertisement

‘Case ‘ inside a ‘group by ‘ clause in SQL Server

I am beginner in SQL Server, I want to write the following query in T-SQL, and I can’t find out how to do it

SELECT 
    SUM(PROSPECTS), 
    MARQUE,
    LANGUAGE 
FROM
    USERS 

CASE Marque IN (0, 16, 30, 36) THEN Group BY MARQUE ELSE Group By Language

Can someone help me please?

Advertisement

Answer

Close…

group by
  CASE Marque IN (0, 16, 30, 36) THEN MARQUE ELSE Language END

But also need to apply same context at the top

SELECT 
    SUM(PROSPECTS), 
    CASE Marque IN (0, 16, 30, 36) THEN MARQUE ELSE Language END MarqLang
FROM
    USERS 
group by
   CASE Marque IN (0, 16, 30, 36) THEN MARQUE ELSE Language END
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement