我正在尝试将Microsoft Access查询转换为SQL Server。
在Access中,SQL是......
TRANSFORM Count(Time_Difference.sc) AS CountOfsc
SELECT Time_Difference.sc
FROM Time_Difference
WHERE (((Time_Difference.Week)>=44 And (Time_Difference.Week)<=48))
GROUP BY Time_Difference.sc
PIVOT Time_Difference.spc;
我尝试转换为SQL ...
SELECT *
FROM
(
SELECT (Time_Difference.sc AS CountOfsc,
Time_Difference.sc,spc
FROM Time_Difference
WHERE (((Time_Difference.Week)>=44 And (Time_Difference.Week)<=48))
GROUP BY Time_Difference.sc
)T
PIVOT
(
COUNT(CountOfsc)
FOR Time_Difference.spc IN (A,B,C,D,E)
)P
有谁知道我做错了什么?
答案 0 :(得分:1)
如果没有看到任何示例数据,我猜您正在寻找类似这样的内容:
select [O1_supplier],A,B,C,D,E
from (
select
[O1_supplier]
, spc
, sc
from Time_Difference
where Time_Difference.Week>=44
and Time_Difference.Week<=48
) as T
pivot (count(sc) for Time_Difference.spc in (A,B,C,D,E))P