【问题标题】:SQL Query PIVOT to MS Access SQL QuerySQL 查询 PIVOT 到 MS Access SQL 查询
【发布时间】:2014-07-10 03:36:37
【问题描述】:

我在 SQL Server 上有这个查询

    ;WITH tmpTbl AS
    (SELECT Kit_Tbl.Kit_Number
           ,Kit_Tbl.Kit_Refrigerant
           ,CompType_Tbl.Component_Type
           ,Comp_List_Tbl.Component_Num
            FROM Kit_Tbl
    INNER JOIN Kit_Library
    ON Kit_Library.Kit_Number = Kit_Tbl.Kit_Number
    INNER JOIN CompType_Tbl
    ON CompType_Tbl.Component_Type = Kit_Library.Component_Type
    INNER JOIN Comp_List_Tbl
    ON Comp_List_Tbl.Component_Type = CompType_Tbl.Component_Type)

    select Kit_Number
         , Kit_Refrigerant
         , [Compressor]
         , [Condensing Unit]
    from
    (
      select Kit_Number, Component_Type, Component_Num, Kit_Refrigerant
      from tmpTbl
    ) d
    pivot
    (
      max(Component_Num)
      for Component_Type in ([Compressor], [Condensing Unit])
    ) piv;

我尝试将其转换为 MS Access 查询,但在 Transform 语句上遇到语法错误:

    TRANSFORM MAX(Comp_List_Tbl.Component_Num) AS Comp_Num
    SELECT Kit_Tbl.Kit_Number,
    CompType_Tbl.Component_Type,MAX(Comp_List_Tbl.Component_Num)
    FROM Comp_List_Tbl INNER JOIN (Kit_Tbl INNER JOIN (Kit_Library INNER JOIN
    CompType_Tbl ON Kit_Library.Component_Type = CompType_Tbl.Component_Type) ON 
    Kit_Tbl.Kit_Number = Kit_Library.Kit_Number) ON (CompType_Tbl.Component_Type = 
    Comp_List_Tbl.Component_Type);
    GROUP BY Kit_Tbl.Kit_Number 
    PIVOT IN CompType_Tbl.Component_Type

谁能帮我解决这个问题?

【问题讨论】:

    标签: sql ms-access ms-access-2007


    【解决方案1】:

    在你的最后一行:

    PIVOT CompType_Tbl.Component_Type
    

    不需要IN

    【讨论】:

      猜你喜欢
      • 2016-01-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-15
      • 2013-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多