Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
所以我有一个 SQL 数据库,其中有一个表,其中有一个名为 City 的列:
一些命名的城市是这样的:
德克萨斯州休斯顿 加利福尼亚州旧金山
我想从城市中删除列和州的缩写,以便它们像这样列出:
休斯顿 旧金山
是否有可以完成此操作的 SQL 命令?
假设 MySQL:
SELECT SUBSTRING_INDEX('San Francisco, CA', ',', 1)
替换San Francisco, CA为您的列名。
San Francisco, CA
假设 SQL Server:
SELECT LEFT('San Francisco, CA', CHARINDEX(',', 'San Francisco, CA')-1)