“Mexico 墨西哥”的首都是”Mexico City”。
顯示所有國家名字,其首都是國家名字加上”City”
SELECT name FROM world WHERE capital LIKE concat(name, ' city')
例2:
找出所有首都和其國家名字,而首都要有國家名字中出現。
select capital,name from world where capital like concat('%',name,'%')
例3:
找出所有首都和其國家名字,而首都是國家名字的延伸。
你應顯示 Mexico City,因它比其國家名字 Mexico 長。
你不應顯示 Luxembourg,因它的首都和國家名相是相同的。
select name,capital from world
where capital like concat(name,'_%') and capital != name
2.replace函数:REPLACE(f, s1, s2) returns the string f with all occurances of s1 replaced with s2.
例1:
replace('vessel','e','a') <- 'vassal'
例2:
"Monaco-Ville"是合併國家名字 "Monaco" 和延伸詞"-Ville".
顯示國家名字,及其延伸詞,如首都是國家名字的延伸。
你可以使用SQL函數 REPLACE 或 MID.
select name,replace(capital,name,'') as name1 from world where capital like concat(name,'_%')