We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
i always get this error and i don't know how to fix it
"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 'cte as "
these are the 2 queries i tried
with cte as (
select
a.id as id,
b.age as age,
a.coins_needed as coins_needed,
a.power as power,
rank() over (partition by age, power order by coins_needed) as rank1
from wands as a
left join wands_property as b on a.code = b.code
where b.is_evil = 0
)
select id, age, coins_needed, power
from cte
where rank1 = 1
order by power desc, age desc;
\\\\\\\\\
select
id, age, power ,coins_needed
from
(select w.id, wp.age, w.power,w.coins_needed,
Row_number()over(partition by w.power,wp.age order by w.coins_needed) as rn
from wands as w
inner join Wands_property as wp
on w.code = wp.code
and wp.is_evil = 0
order by w.power desc, wp.age desc) rr
where rn =1
order by power desc, age desc
;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Ollivander's Inventory
You are viewing a single comment's thread. Return to all comments →
i always get this error and i don't know how to fix it "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 'cte as "
these are the 2 queries i tried with cte as ( select a.id as id, b.age as age, a.coins_needed as coins_needed, a.power as power, rank() over (partition by age, power order by coins_needed) as rank1 from wands as a left join wands_property as b on a.code = b.code where b.is_evil = 0 ) select id, age, coins_needed, power from cte where rank1 = 1 order by power desc, age desc;
\\\\\\\\\
select id, age, power ,coins_needed from (select w.id, wp.age, w.power,w.coins_needed, Row_number()over(partition by w.power,wp.age order by w.coins_needed) as rn from wands as w inner join Wands_property as wp on w.code = wp.code and wp.is_evil = 0 order by w.power desc, wp.age desc) rr where rn =1 order by power desc, age desc ;