sqlzoo

https://sqlzoo.net/wiki/SELECT_names

  • Find the capital and the name where the capital includes the name of the country.

select capital, name from world where capital like concat('%',name,'%')

  • 14.Find the capital and the name where the capital is an extension of name of the country.
    You should include Mexico City as it is longer than Mexico. You should not include Luxembourg as the capital is the same as the country.
    SELECT capital ,name FROM world WHERE capital like concat(name,'%') AND name != capital;

  • For Monaco-Ville the name is Monaco and the extension is -Ville.
    Show the name and the extension where the capital is an extension of name of the country.
    You can use the SQL function REPLACE.
    select name, replace(capital, name,'') from world where capital like concat(name,'_%');

https://sqlzoo.net/wiki/SELECT_from_WORLD_Tutorial#Large_Countries

你可能感兴趣的:(sqlzoo)