选择MIN / MAX列lat long

时间:2018-03-28 05:07:33

标签: mysql sql

我有一个看起来像这样的列

enter image description here

如何获得最小值和最大值?

这是预期值,右侧是已排序的值

enter image description here

2 个答案:

答案 0 :(得分:1)

Select membername From
(Select membername,
substring_index ( membername,',',1)+substring_index ( membername,',',-1) as total
From Table1) T1
Inner Join 
(
Select Max(total) total1,Min(total) total2 From (
SELECT membername,
       substring_index ( membername,',',1)+substring_index ( membername,',',-1) as total
From Table1)T) T2
ON T1.total=T2.total1
OR T1.total=T2.total2

现场演示

  

http://sqlfiddle.com/#!9/5f6410/1

答案 1 :(得分:1)

要根据问题中的预期结果对表格进行排序,您只需要:

SELECT latlong 
FROM someTable
ORDER BY latlong ASC