select substring(PropertyAddress, 1, (locate(',', PropertyAddress) -1 )) as address,
substring(PropertyAddress, (locate(',', PropertyAddress) +1, length(PropertyAddress))) as city
from nashvillehousing;
第一个子字符串查询工作,但第二个没有,不知道我在这里错过了什么。
你的第一次选择很好,问题在于第二次选择:
SELECT
SUBSTRING(PropertyAddress, (LOCATE(',', PropertyAddress) +1), LENGTH(PropertyAddress)) AS city
FROM nashvillehousing;
我相信你已经意识到你的错误,只是为了说清楚,SUBSTRING的语法是:
SUBSTRING(string, start, length)
一个)
是所有你放错地方。