我工作throught挑戰這裏詳述: https://www.hackerrank.com/challenges/harry-potter-and-wandsSQL語法錯誤 - 奧利凡德的庫存
,並想出了這個解決方案,但我得到一個語法錯誤消息,而不是或結果我期待。我的代碼:
With
m As (Select
w.power,
wp.age,
Min(w.coins_needed) As min_coins
From
wands w Join
wands_property wp
On wp.code = w.code
Where
wp.is_evil = 0
Group By
w.power, wp.age)
Select
w.id,
wp.age,
w.coins_needed,
w.power
From
wands w Join
wands_property wp
On wp.code = w.code
Join m
On m.power = w.power And m.age = wp.age And m.min_coins =
w.coins_needed
Where
wp.is_evil = 0
Order By
w.power Desc,
wp.age Desc,
w.coins_needed Desc
從hackerrank錯誤消息:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'm As (Select
w.power,
wp.age,
Min(w.coins_needed) As min_coins' at line 2
我看不出有什麼不妥。我錯過了什麼?
我不確定MySQL支持cte的? – jarlh
@jarlh是正確的,MySQL沒有'WITH'。 – Barmar