79161671

Date: 2024-11-06 07:36:47
Score: 0.5
Natty:
Report link

As my experience, Pivot function best works on CTEs and subqueries from which the result sets do not have primary keys. Take a look at the following Example:

The schema of the Employee table is:

schema of the Employee

SELECT IT, ACCOUNT, SALES FROM [dbo].[Employee] pivot( MAX([salary]) for [dept_id] in (IT, ACCOUNT, SALES) ) as cnt;

WITH ProjectdEmployees as (SELECT dept_id, salary from [dbo].[Employee])

SELECT IT, ACCOUNT, SALES FROM ProjectdEmployees pivot( MIN ([salary]) for [dept_id] in (IT, ACCOUNT, SALES) ) as cnt;

enter image description here

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (0.5):
Posted by: BehiAlav