clickhouse计算前后两点间经纬度距离

问题

计算如图所示前后两点经纬度的距离?

方法

1、用开窗函数将如图所示数据下移一行

sql 复制代码
select
	longitude lon1,
	latitude lat1,
	min(longitude) over(
	order by time1 asc rows between 1 PRECEDING and 1 PRECEDING) lon2,
	min(latitude) over(
	order by time1 asc rows between 1 PRECEDING and 1 PRECEDING) lat2
from
	table1

完整sql

sql 复制代码
select
	time1 ,
	lon1,
	lat1,
	lon2,
	lat2,
	greatCircleDistance(a.lon1,
	a.lat1,
	a.lon2,
	a.lat2) distance
from
	(
	select
		time1,
		longitude lon1,
		latitude lat1,
		min(longitude) over(
		order by time1 asc rows between 1 PRECEDING and 1 PRECEDING) lon2,
		min(latitude) over(
		order by time1 asc rows between 1 PRECEDING and 1 PRECEDING) lat2
	from
		table1

3、简化版sql

sql 复制代码
select
	time1 ,
	longitude,
	latitude,
	greatCircleDistance(longitude , latitude ,
	min(longitude) over(
	order by time1 asc rows between 1 PRECEDING and 1 PRECEDING),
	min(latitude) over(
	order by time1 asc rows between 1 PRECEDING and 1 PRECEDING)) distance
from
	table1
相关推荐
Altruiste1 天前
minikube 搭clickhouse 集群
clickhouse·kubernetes
zandy10111 天前
HENGSHI SENSE加速引擎架构深度解析:MPP列存与ClickHouse物化视图实战
clickhouse·架构·企业级bi·mpp列存
*勇往直前*1 天前
unbutu安装clickhouse,并且远程连接,使用教程,原理
clickhouse
StarRocks_labs4 天前
KaptureCX 大规模实时分析架构演进:基于 RisingWave 与 StarRocks 的最佳实践
starrocks·sql·clickhouse·ai赋能·kapture
l1t4 天前
DeepSeek总结的pg_clickhouse v0.3.0的新特性
clickhouse·postgresql
bzmK1DTbd4 天前
ClickHouse列式存储:海量数据分析利器
clickhouse·oracle·数据分析
不恋水的雨6 天前
docker安装clickhouse数据库容器
clickhouse·docker·容器
麦兜和小可的舅舅6 天前
ClickHouse Dist表的Replica选择逻辑深度解析-- Custom Key以及Sample的执行逻辑
c++·clickhouse·distribute·shard
布吉岛的石头6 天前
ClickHouse性能优化:OLAP数据库实战,让查询飞起来
数据库·clickhouse·性能优化