Skip to content
Advertisement

mysql how to show order number in result

so here is the query

select * from test order by pow(c1 - 8, 2) + pow(c2 - 5, 2) limit 3 

is there any way to show order section -> “pow(c1 – 8, 2) + pow(c2 – 5, 2)” for each record in result ?

Advertisement

Answer

Just include it in the select:

select t.*, pow(c1 - 8, 2) + pow(c2 - 5, 2) as distance_squared
from test t
order by distance_squared
limit 3 
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement