Skip to content

Instantly share code, notes, and snippets.

@KWKdesign
Last active August 29, 2015 14:05
Show Gist options
  • Save KWKdesign/012a96c095832d0769d4 to your computer and use it in GitHub Desktop.
Save KWKdesign/012a96c095832d0769d4 to your computer and use it in GitHub Desktop.
Schemaverse: Ships Heatmap SQL
with max_xy as (
select greatest(
max( abs( location_x ) ),
max( abs( location_y ) )
) v
from planets
),
scale as (
select m * ceil( v / m ) scale from (
select 10 ^ floor( log( v ) ) m, v
from max_xy
)a
)
select count(1),
width_bucket( location[0], -scale, scale, 100 ) xb,
width_bucket( location[1], -scale, scale, 100 ) yb
from ship_flight_recorder
cross join scale
where 1=1
and tic = ( select last_value-1 from tic_seq )
and location[0] between -scale and scale
and location[1] between -scale and scale
group by xb, yb
order by xb, yb
;
-- Schemaverse Ships Heatmap SQL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment