![](/img/trans.png)
[英]How to SUM two highest salary on table EMP on deptno ( deptno 10,20,30) using BREAK and COMPUTE SUM?
[英]Pivot table deptno on columns and count and salary on rows?
有人可以糾正我在旋轉行和列時我做錯了什么嗎?
--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
試試這個-
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.