我正在尝试计算每个具有多个预订位置id的唯一订单号

d8tt03nd  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(203)

我的代码怎么了?在执行这些行时,我从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

我犯了这样的错误
由于内部错误,不支持这种类型的相关子查询模式
谢谢你的帮助。
萨利赫

ntjbwcob

ntjbwcob1#

是否要查找具有多个位置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
)

建议,
请在投递前格式化代码。
问题还不清楚,张贴几行有代表性的数据集和什么是预期的产出。

相关问题