cus*_*OOM 6 mysql sql database
任何人都可以告诉我在mysql中订购结果的问题
问题
不能通过距离以外的任何列进行排序
SELECT * , (
(
(
ACOS( SIN( (
'56.3168322' * PI( ) /180 ) ) * SIN( (
`lat` * PI( ) /180 )
) + COS( (
'56.3168322' * PI( ) /180 )
) * COS( (
`lat` * PI( ) /180 )
) * COS( (
(
'-5.414989099999957' - `lng`
) * PI( ) /180 )
)
)
) *180 / PI( )
) *60 * 1.1515 * 1.609344
) AS `distance`
FROM `incidents`
HAVING `distance` <=3
ORDER BY `distance` ASC
LIMIT 0 , 30
Run Code Online (Sandbox Code Playgroud)
例如,当我尝试根据date_incident行中的日期对列进行排序时
SELECT * , (
(
(
ACOS( SIN( (
'56.3168322' * PI( ) /180 ) ) * SIN( (
`lat` * PI( ) /180 )
) + COS( (
'56.3168322' * PI( ) /180 )
) * COS( (
`lat` * PI( ) /180 )
) * COS( (
(
'-5.414989099999957' - `lng`
) * PI( ) /180 )
)
)
) *180 / PI( )
) *60 * 1.1515 * 1.609344
) AS `distance`
FROM `incidents`
HAVING `distance` <=3
ORDER BY `date_incidents` ASC
LIMIT 0 , 30
Run Code Online (Sandbox Code Playgroud)
在上面它没有排序但仍然返回结果.
任何帮助都会很棒.
标准 SQL 不允许HAVING子句命名GROUP BY子句中未找到的任何列,除非它包含在aggregate function. 中,但 MySQL 允许在子句中引用任何别名HAVING。前任:
SELECT name, AVG(age) AS a FROM tables
GROUP BY name
HAVING a > 50;
Run Code Online (Sandbox Code Playgroud)