簡體   English   中英

調整 CTE 以在 MySql 的 Azure 數據庫上工作

[英]Adjusting CTE to work on Azure Database for MySql

我已經檢查了與我的問題類似的答案 我有一個在以前的 SQL 服務器上運行的查詢,現在整個數據庫已遷移到 Azure MySql,查詢不再有效:

適用於 MySQL 服務器的查詢

WITH cte_1 AS
(
  SELECT 
    1 AS col1, 
    2 AS col2

),

cte_2 AS
(
  SELECT 
    3 AS col3,
    4 AS col4

)

SELECT 
    normal_table.col0, 
    normal_table.col00,
    cte_1.col1,
    cte_1.col2,
    cte_2.col3,
    cte_2.col4
    
FROM normal_table

LEFT JOIN
    cte_1
        ON normal_table.col0 = cte_1.col1
        
LEFT JOIN
    cte_2
        ON normal_table.col0 = cte_2.col3

我得到一個錯誤:

And I get an error stating:
`ou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'cte_1 AS (` 

我試過了:

        
-- with q as (<query>) select .... from q 
-- becomes 
-- select ... from (<query>) as q       
        
SELECT 
    normal_table.col0, 
    normal_table.col00,
    cte_1.col1,
    cte_1.col2,
    cte_2.col3,
    cte_2.col4
    
FROM normal_table
left join (
SELECT 
    1 AS col1, 
    2 AS col2) as cte_1
    
left join (
SELECT 
    1 AS col3, 
    2 AS col4) as cte_2

我應該使用什么結構來調整 SQL CTE 以在 Azure MySql 上工作?

我也已閱讀此頁面並嘗試調整我的代碼但沒有成功。

我用了:

SELECT 
    normal_table.col0, 
    normal_table.col00,
    cte_1.col1,
    cte_1.col2,
    cte_2.col3,
    cte_2.col4

FROM normal_table
left join (
SELECT 
    1 AS col1, 
    2 AS col2) as cte_1
    ON normal_table.col0 = cte_1.col1

left join (
SELECT 
    1 AS col3, 
    2 AS col4) as cte_2
    ON normal_table.col0 = cte_2.col3

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM