Skip to content

Instantly share code, notes, and snippets.

@jsanz
Created September 5, 2016 09:12
Show Gist options
  • Save jsanz/13e635b55a0bbee5a4acb27b4a3e7c48 to your computer and use it in GitHub Desktop.
Save jsanz/13e635b55a0bbee5a4acb27b4a3e7c48 to your computer and use it in GitHub Desktop.
SQL: Stacking Chips
WITH
data as (
SELECT
cartodb_id,
ST_SnapToGrid(the_geom,.5) as the_geom
FROM team
),
m AS (
SELECT array_agg(cartodb_id) id_list, the_geom, ST_Y(the_geom) y
FROM data
GROUP BY the_geom
ORDER BY y DESC
),
f AS (
SELECT generate_series(1, array_length(id_list,1)) p, unnest(id_list) cartodb_id, the_geom
FROM m
)
SELECT
ST_Transform(ST_Translate(
f.the_geom,
0,
f.p*.22
),3857) the_geom_webmercator,
f.cartodb_id,
q.emp_id,
q.workemail,
q.displayname,
q.gender,
q.jobtitle,
q.department,
q.location,
q.division,
q.photourl
FROM f, team q
WHERE f.cartodb_id = q.cartodb_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment