简体   繁体   中英

How can I rewrite this query by not having AS?

I'm completing a HackerRank challenge, but the documentation says I should not use the AS keyword:

在此处输入图像描述

I need to rewrite this query in MySQL so it doesn't include the AS in WITH A AS , nor AS in SELECT...AS test

WITH A AS (
    SELECT DISTINCT
        MAX( LENGTH( customer_id ) ) AS test
    FROM
        orders

    UNION

    SELECT DISTINCT
        MIN( LENGTH( customer_id ) )
    FROM
        orders
)
SELECT
    test,
    LENGTH(test)
FROM
    A

The WITH clause is using for declare a VIEW, so you can rewrite it like below


SELECT
    test,
    LENGTH(test)
FROM
    (
 SELECT DISTINCT
        MAX( LENGTH( customer_id ) ) AS test
    FROM
        orders

    UNION

    SELECT DISTINCT
        MIN( LENGTH( customer_id ) )
    FROM
        orders)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM