Answer Posted / samba shiva reddy . m
creating pivot table:
Columns as Rows
below statement will give as it is data
select
PS.Name, P.Color, PIn.Quantity
from Production.Product P
inner join Production.ProductSubcategory PS
on PS.ProductSubcategoryID = P.ProductSubcategoryID
left join Production.ProductInventory PIn
on P.ProductID = PIn.ProductID
This statement will change the columns as rows
select
*
from
(
select
PS.Name, P.Color, PIn.Quantity
from Production.Product P
inner join Production.ProductSubcategory PS
on PS.ProductSubcategoryID = P.ProductSubcategoryID
left join Production.ProductInventory PIn
on P.ProductID = PIn.ProductID
) DataTable
PIVOT
(
SUM(Quantity)
FOR Color
IN (
[Black],[Blue],[Grey],[Multi],[Red],
[Silver],[Silver/Black],[White],[Yellow]
)
) PivotTable
| Is This Answer Correct ? | 2 Yes | 4 No |
Post New Answer View All Answers
Can you explain different types of locks in sql server?
Explain comment on transactions?
let's assume you have data that resides on sql server 6.5. You have to move it sql server 7.0. How are you going to do it? : Sql server database administration
What is difference between inner join and full join?
Does table partitioning improve performance?
what is a schema in sql server 2005? : Sql server database administration
How to create a view with data from multiple tables?
How to execute a sql statement using mssql_query()?
Why truncate is ddl?
If any stored procedure is encrypted, then can we see its definition in activity monitor?
What are some examples of schemas?
What number aggregate functions are accessible there in sql?
What are the differences in Clustering in SQL Server 2005 and 2008 or 2008 R2?
Write a SQL command to insert and update only a particular field?
How do I completely remove sql server instance?