0

我的代码有什么问题?执行这些行时,我从 Redshift 收到错误消息。

SELECT
COUNT (
        DISTINCT (
            CASE
                WHEN EXISTS(
                    (
                        select
                            1
                        from
                            (
                                select
                                    ci.order_no,
                                    count(ci.booking_location_id) as cnt
                                from
                                    oms_core_inventory_booking_detail ci
                                group by
                                    ci.order_no
                            ) cibd
                            where cibd.cnt > 1
                            and co.order_no = cibd.order_no
                    )
                ) THEN co.order_no
                else NULL
            END
        )
    ) AS "SP受注数"
from
table co

我收到这样的错误

由于内部错误,不支持这种类型的相关子查询模式

感谢您的到来帮助。

萨利赫

4

1 回答 1

0

您是否正在查找具有多个位置 ID 的订单 ID 的数量?

SELECT COUNT(*) as order_id_cnt FROM (
SELECT ci.order_no,
       COUNT(ci.booking_location_id) AS cnt
FROM oms_core_inventory_booking_detail ci
GROUP BY ci.order_no
HAVING COUNT(ci.booking_location_id)>1
)

建议,

  1. 请在发布前格式化代码。
  2. 问题尚不清楚,发布几行代表性数据集以及预期输出是什么。
于 2020-07-22T23:27:56.480 回答