1

问题是:

如果城市名称以字母“Sa”开头并以“s”结尾,请列出所有城市及其地区和国家名称。按城市名称排序。

我不知道该怎么做的部分是“城市名称以字母'Sa'开头并以's'结尾。”

这就是我所拥有的:

SELECT ci.name AS city, ci. district, c.name AS country
FROM lab2.city ci INNER JOIN lab2.country c                    
ON (ci.country_code = c.country_code)
WHERE ci.name ~^ 'Sa' <----------------------This is the problem line. 
ORDER BY ci.name ASC;
4

1 回答 1

1

这个问题听起来像是在寻找一种模式。在这种情况下,您可以使用LIKE.

SELECT   ci.name AS city, 
         ci.district, 
         c.name AS country
FROM     lab2.city ci 
         INNER JOIN lab2.country c
            ON ci.country_code = c.country_code
WHERE    ci.name LIKE 'Sa%s' 
ORDER    BY ci.name ASC;
于 2013-02-10T05:17:48.867 回答