0

I have a list of stores and the turnover:

SELECT
CASE WHEN SELLER_ID IN ('X','Y') THEN 'SALON' ELSE STORES_ID END AS 'STORES', 
SUM (TURNOVER)
FROM PIECE
GROUP BY STORES_ID ,SELLER_ID 

The problem is that I don't want to use the field SELLER_ID in the group by:

Result:

STORE TURNOVER
S1    500
S1    500
S2    600
S2    600
S3    550
S3    550

Excepted result: I want to have the sum turnover for each store in one row, but I want only to divis one store in 2 rows when SELLER_ID IN ('X','Y')

Let's say that S3 it's the store that I want to devis:

S1     500
S2     300
S3     250
SALON  200
Dale K
  • 25,246
  • 15
  • 42
  • 71

1 Answers1

0

You can also use the CASE statement in your GROUP BY clause:

SELECT
CASE WHEN SELLER_ID IN ('X','Y') THEN 'SALON' ELSE STORES_ID END AS 'STORES', 
SUM (TURNOVER)
FROM PIECE
GROUP BY CASE WHEN SELLER_ID IN ('X','Y') THEN 'SALON' ELSE STORES_ID END
Wouter
  • 2,881
  • 2
  • 9
  • 22