Advertisement
Guest User

Untitled

a guest
May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.53 KB | None | 0 0
  1. INNER JOIN (
  2.               SELECT node_id,
  3.                      SUM(r * weight) / (
  4.                        SQRT(SUM(COALESCE(r, 1) * weight)^2 +
  5.                          SUM(COALESCE(g, 1) * weight)^2 +
  6.                            SUM(COALESCE(b, 1) * weight)^2)
  7.                      ) AS r,
  8.                      SUM(g * weight) / (
  9.                        SQRT(SUM(COALESCE(r, 1) * weight)^2 +
  10.                          SUM(COALESCE(g, 1) * weight)^2 +
  11.                            SUM(COALESCE(b, 1) * weight)^2)
  12.                      ) AS g,
  13.                      SUM(b * weight) / (
  14.                        SQRT(SUM(COALESCE(r, 1) * weight)^2 +
  15.                          SUM(COALESCE(g, 1) * weight)^2 +
  16.                            SUM(COALESCE(b, 1) * weight)^2)
  17.                      ) AS b
  18.                 FROM node_populations
  19.                   INNER JOIN populations ON node_populations.population_id = populations.id
  20.                   LEFT OUTER JOIN (
  21.                     VALUES
  22.                       ('OG Kush', 0.258, 0.431, 0.69),
  23.                       ('Landrace', 0.25, 0.549, 0.384),
  24.                       ('Skunk', 0.839, 0.329, 0.329),
  25.                       ('Berry', 0.624, 0.49, 0.627),
  26.                       ('CBD', 0.929, 0.631, 0.459),
  27.                       ('Hemp', 0.518, 0.529, 0.431)
  28.                   ) AS colors(popname, r, g, b) ON colors.popname = populations.name
  29.                 WHERE populations.constellation_id = :constellation_id
  30.                 GROUP BY node_id
  31.             )AS pops ON pops.node_id = nodes.id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement