我正在完成 HackerRank 挑戰,但文件說我不應該使用 AS
關鍵字:
我需要在MySQL 中重寫此查詢,以便它不包含WITH A AS
中的AS
,也不包含SELECT...AS test 中的AS
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
P粉4974634732024-01-17 14:21:34
WITH 子句用於宣告 VIEW,因此您可以像下面這樣重寫它
SELECT test, LENGTH(test) FROM ( SELECT DISTINCT MAX( LENGTH( customer_id ) ) AS test FROM orders UNION SELECT DISTINCT MIN( LENGTH( customer_id ) ) FROM orders)