SELECT
feature_name,
( 3959 * acos( cos( radians(37) ) * cos( radians( lat ) )
* cos( radians( long ) - radians(-122) ) + sin( radians(37) )
* sin( radians( lat ) ) ) ) AS distance
FROM
geo_features
HAVING
distance < 25
ORDER BY
distance
答案 0 :(得分:1)
假设这个静态导入:
import static org.jooq.impl.DSL.*;
以下是如何编写查询:
GeoFeatures f = Tables.GEO_FEATURES;
Field<Double> distance =
val(3959.0).mul(acos(cos(rad(37.0)))).mul(cos(rad(f.LAT)))
.mul(rad(f.LONG).sub(rad(-122.0)).add(sin(rad(37.0)))
.mul(sin(rad(f.LAT))).as("distance")
DSL.using(configuration)
.select(
f.FEATURE_NAME,
distance
)
.from(f)
.having(distance.lt(25.0))
.orderBy(distance)
这些是要记住的关键事项:
org.jooq.impl.DSL
* = mul()
,+ = add() or plus()
,- = sub() or minus()
val()
(对于绑定变量)或inline()
(用于内联)