SQLZOO-练习答案SELECT basics/SELECT names

SELECT basics/SELECT names 练习答案

11、SELECT name fromworld

where name=capital


12、select name fromworld where capital like concat(NAME,’ City')

说明:concat()意为将字符链接起来。注意‘city’前需要留一个空格,否则答案错误。


13、selectcapital,name

from world

where capital like concat('%',name,'%')

说明:找出首都名字含有国家名称的国家。Concat()此处仍然为连接字符的函数,“%”为通配符,此处的百分号通配符需要添加用单引号。另外,按照题意,挑选顺序应该是先capital,然后name。


14、selectcapital,name

from world

where capital like concat('%',name,'%') andcapital not like name

或者

Select capital,name

From world

Where capital like concat(‘%’,name,’%’) andcapital!=name


15、不明白,未知,待解

Q:

For Monaco-Ville the name is Monaco and theextension is -Ville.

Show the name and the extension where thecapital is an extension of name of the country.

You can use the SQL function REPLACE.


A:

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


或者


SELECT name, REPLACE(capital, name, '') FROMworld WHERE capital LIKE concat('%', name, '%') AND capital > name


或者


selectname,mid(replace(capital,name,'1'),2) 

from world 

where capital like concat(name,'_%') 

你可能感兴趣的:(SQLZOO-练习答案SELECT basics/SELECT names)