1

是否可以在 ABAP CDS 查询中进行数据透视查询?有没有一种方法可以像我们在 SQL Server 和 MySQL 中一直在做的那样实现这一点?

4

1 回答 1

1

不,目前它在 ABAP CDS 和 HANA 中都不受本机支持。

您可以使用多种解决方法来模拟枢轴行为:

  1. [示例]COUNT一起旋转UNION ALL

    select vendor_id, sum("E1") AS "E1", SUM("E2") AS "E2", SUM("E3") AS "E3"
    FROM
    (
    select vendor_id, COUNT(NUM) as "E1", 0 AS "E2" , 0 AS "E3"
    from "ABHISHEAGRAW".
    WHERE EMP_ID = 'E1' GROUP BY vendor_id
    union all
    select vendor_id, 0 AS “E1”, COUNT(NUM) as "E2", 0 AS "E3"
    from "ABHISHEAGRAW".
    WHERE EMP_ID = 'E2' GROUP BY vendor_id
    union all
    select vendor_id, 0 AS “E1”, 0 as "E2", COUNT(NUM) AS "E3"
    from "ABHISHEAGRAW".
    WHERE EMP_ID = 'E3' GROUP BY vendor_id
    ) GROUP BY vendor_id ORDER BY vendor_id
    
  2. COUNT通过[示例]旋转CASE

    select vendor_id, sum("E1") AS "E1", SUM("E2") AS "E2", SUM("E3") AS "E3"
    FROM
    (
    select vendor_id, CASE (EMP_ID) WHEN 'E1'
    THEN 1
    ELSE 0
    END as "E1",
    CASE (EMP_ID) WHEN 'E2'
    THEN 1
    ELSE 0
    END as "E2",
    CASE (EMP_ID) WHEN 'E3'
    THEN 1
    ELSE 0
    END as "E3"
    from “ABHISHEAGRAW”.
    )GROUP BY vendor_id ORDER BY vendor_id
    
  3. 使用 CASE 进行透视和分组[示例]

给定的片段是 HANA 示例,但它们可以适应 ABAP CDS。如果您提供案例的MCVE,我们可以为您提供可能的解决方案。

于 2019-10-27T20:14:56.347 回答