0

行と列をピボットするのが間違っていることを誰でも修正できますか?

--Trying to count no. of employees in each dept and pivoting it as deptno on columns and counts of no. of employees
-- rows

SELECT 10, 20, 30
FROM emp
PIVOT
(
count(deptno)
FOR empno IN ([10],[20],[30])
)
as pt

--Trying to sum of salary in each dept and pivoting it as deptno on columns and sum of salary of rows but same repeating nature
-- rows

SELECT 10, 20, 30
FROM emp
PIVOT
(
deptno(deptno)
FOR deptno IN ([10],[20],[30])
)
as pt
4

1 に答える 1

1

これを試してみてください -

DECLARE @temp TABLE (deptno INT)

INSERT INTO @temp (deptno)
VALUES (10),(20),(20), (40),(30)

SELECT [10], [20], [30]
FROM @temp
PIVOT
(
    COUNT(deptno)
    FOR deptno IN ([10], [20], [30])
) pt
于 2013-04-24T10:01:37.580 に答える