dimensionav
asked on
How to reorganize an sql query?
HI
I have a query that gives me the following information:
Code, ProductName, Size
1 Blouse S
2 Blouse S
3 Skirt M
4 Pants L
The idea is to reorganize the information like this:
ProductName, SizeS, SizeM, SizeL
Blouse 2 0 0
Skirt 0 1 0
Pants 0 0 1
Any ideas?
Regards.
I have a query that gives me the following information:
Code, ProductName, Size
1 Blouse S
2 Blouse S
3 Skirt M
4 Pants L
The idea is to reorganize the information like this:
ProductName, SizeS, SizeM, SizeL
Blouse 2 0 0
Skirt 0 1 0
Pants 0 0 1
Any ideas?
Regards.
you might want to use pivot query
try something like this:
SELECT * FROM (SELECT Title,Code,'Size'+Size as sz FROM Table_1) Data
PIVOT (COUNT(Code)
FOR sz IN([SizeS],[sizeM],[SizeL] )) AS CountSize
try something like this:
SELECT * FROM (SELECT Title,Code,'Size'+Size as sz FROM Table_1) Data
PIVOT (COUNT(Code)
FOR sz IN([SizeS],[sizeM],[SizeL]
ged325, you are missing some commas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sum (case when Size = 'S' then 1 else 0 end) SizeS
sum (case when Size = 'M' then 1 else 0 end) SizeM
sum (case when Size = 'L' then 1 else 0 end) SizeL
from <Table>
group by productName