Last active
August 29, 2015 14:05
-
-
Save KWKdesign/012a96c095832d0769d4 to your computer and use it in GitHub Desktop.
Schemaverse: Ships Heatmap SQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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