'Show the name and the extension where the capital is an extension of name of the country from the table CITY

For example, In 'Monaco-Ville' the name is Monaco and the extension is -Ville. This problem is from SQLZOO. I am having trouble making my solution look like the way the site requires.

SELECT name, REPLACE( capital, name, ' ')
FROM world
WHERE capital LIKE concat(name, '_%')

MY SOLUTION :

name        REPLACE( capi..
Andorra     la Vella
Guatemala   City
Kuwait      City
Mexico      City
Monaco      -Ville
Panama      City

what the answer should be...

name        ext
Andorra     la Vella
Guatemala   City
Kuwait      City
Mexico      City
Monaco      -Ville
Panama      City


Solution 1:[1]

You have an extra space between your two quotes: ' '.

If you amend it to SELECT name, REPLACE( capital, name, '') it will give you the right answer; I am reviewing this same exercise at the moment.

Solution 2:[2]

Try using this:

SELECT name, REPLACE( capital, name, '') as 'ext'
FROM world
WHERE capital LIKE concat(name, '_%')

Solution 3:[3]

SELECT name, REPLACE(capital, name, '') AS ext
FROM world
WHERE capital LIKE CONCAT('%', name, '%')
AND LENGTH(capital) > LENGTH(name)

Solution 4:[4]

The answer can be this:

SELECT name, REPLACE( capital, name, '')
FROM world
WHERE capital LIKE concat(name, '%_')

And I have meet some other question.

Sounds like that sqlzoo website has wrong setting for this question answer.

enter image description here

when we click the "Submit SQL" button, the browser send a post request named 'sqlgo'.And there has our solution 'sql' and the sqlzoo offical answer 'answer'.The problem is that the sqlzoo offical answer doesn't work well.

select name,mid(capital,length(name)+1) ext
from world
where capital like concat(name,'_%')

So check the response for 'sqlgo',we can find the error information.

enter image description here

Sqlzoo checks the difference between the result of our sql and the result of the answer sql. But now the answer sql doesn't work, so we can't get the correct answer.

we can modify the sql Engine to MySql from Microsoft SQL by the gear icon in the upper right corner. Then it could work well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adrian Mole
Solution 2 סטנלי גרונן
Solution 3 Lucas Stinson
Solution 4