我们可以在mysql中使用字符串函数从单个查询中提取多个数据吗?

我们可以在mysql中使用字符串函数从单个查询中提取多个数据吗?,mysql,substring,Mysql,Substring,我想知道是否可以使用字符串操作通过单个查询提取多个数据 这就是我要找的 我的查询返回我 +-----------------------------------------+ | geodata | +-----------------------------------------+ | {"lat"=>"28.644348", "lon"=>"77.219682" | +-----------------------

我想知道是否可以使用字符串操作通过单个查询提取多个数据

这就是我要找的 我的查询返回我

+-----------------------------------------+
|               geodata                   |
+-----------------------------------------+
| {"lat"=>"28.644348", "lon"=>"77.219682" |
+-----------------------------------------+
我可以通过任何字符串查询提取
lat
值和
lon
值吗

我尝试并成功地提取了一个值

谁能建议我怎么做


当然,我可以在将这些数据拉到rails应用程序后执行此操作,但我正在考虑直接从查询中拉取这些数据。

是的,如果您显示的模式相同,则可以执行此操作

mysql> select replace(substring_index(substring_index('{"lat"=>"28.644348", "lon"=>"77.219682"','"lat"=>',-1),',',1),'"','') as lat;
+-----------+
| lat       |
+-----------+
| 28.644348 |
+-----------+
1 row in set (0.00 sec)

mysql> select replace(substring_index(substring_index('{"lat"=>"28.644348", "lon"=>"77.219682"','"lon"=>',-1),',',1),'"','') as lon;
+-----------+
| lon       |
+-----------+
| 77.219682 |
+-----------+
因此,最后您可以将这两个选项组合为一个选项

select 
replace(substring_index(substring_index(geodata,'"lat"=>',-1),',',1),'"','') as lat,
replace(substring_index(substring_index(geodata,'"lon"=>',-1),',',1),'"','') as lon
from your_table

向我们展示您尝试了什么,我们可以从那里开始。选择replace(子字符串_index('{“lat”=>“28.644348”,“lon”=>“77.219682”,'',-2),'','';