【问题标题】:Transform and PIVOT Microsoft Access - SQL Server转换和 PIVOT Microsoft Access - SQL Server
【发布时间】:2017-04-21 16:13:37
【问题描述】:

我正在尝试将 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

有谁知道我做错了什么?

【问题讨论】:

    标签: sql sql-server ms-access pivot transform


    【解决方案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
    

    【讨论】:

    • 抱歉,我在粘贴代码时打错了字。问题是我在“FOR”中不断收到错误“列名无效”
    • @tlech 提供了一些示例数据和所需结果的示例,这将使事情变得更加简单。
    猜你喜欢
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 2017-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多