Skip to content

Oracle compatibility mode: unexpected Column alias is not specified exception in CTE #4139

@manticore-projects

Description

@manticore-projects

Greetings!

-- WITH fails: Column alias is not specified for expression "(COUNT(CUSTOMER_ID) > 1)";
WITH d AS (
        SELECT customer_id
        FROM (  SELECT DISTINCT
                    customer_id
                    , id_customer_type
                FROM risk.ext_counterparty_classification )
        GROUP BY customer_id
        HAVING Count( customer_id ) > 1 )
SELECT *
FROM risk.ext_counterparty_classification a
    INNER JOIN d
            on a.customer_id = d.customer_id
WHERE id_customer_type = 'Multi Financial Institution'
;


-- although SUB Select works
SELECT *
FROM risk.ext_counterparty_classification a
    INNER JOIN (    SELECT customer_id
                    FROM (  SELECT DISTINCT
                                customer_id
                                , id_customer_type
                            FROM risk.ext_counterparty_classification )
                    GROUP BY customer_id
                    HAVING Count( customer_id ) > 1 ) d
        ON a.customer_id = d.customer_id
WHERE id_customer_type = 'Multi Financial Institution'
;

Without the HAVING clause, the WITH also works (but of course the result set would not match expectation).
Latest 2.2.232 and both queries should be the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions