Skip to content

Instantly share code, notes, and snippets.

@Danyboy
Last active May 18, 2016 00:00
Show Gist options
  • Select an option

  • Save Danyboy/d94421387e5a67a85880c26cc8f01ba2 to your computer and use it in GitHub Desktop.

Select an option

Save Danyboy/d94421387e5a67a85880c26cc8f01ba2 to your computer and use it in GitHub Desktop.

Revisions

  1. Danyboy revised this gist May 18, 2016. 1 changed file with 14 additions and 15 deletions.
    29 changes: 14 additions & 15 deletions compatibility.sql
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,14 @@
    SELECT id, link, name, hours_together, coef
    FROM (
    SELECT my_users.user_id, COUNT (*)::float / 12 AS hours_together, COUNT(*)::float / user_coef.their_hours AS coef
    FROM online{$current_user} LEFT JOIN online{$current_user} AS my_users
    ON my_users.status = online{$current_user}.status
    INNER JOIN (SELECT user_id, COUNT(*) AS their_hours
    FROM online{$current_user}
    GROUP BY user_id) AS user_coef
    ON user_coef.user_id = my_users.user_id
    WHERE online{$current_user}.user_id = {$user}
    GROUP BY online{$current_user}.user_id, my_users.user_id, user_coef.their_hours
    ORDER BY hours_together DESC
    ) AS my_comp
    JOIN users{$current_user}
    ON (my_comp.user_id = id);
    SELECT id, link, name, hours_together, coef
    FROM (
    SELECT my_users.user_id, COUNT (*)::float / 12 AS hours_together, COUNT(*)::float / user_coef.their_hours AS coef
    FROM online{$current_user} LEFT JOIN online{$current_user} AS my_users
    ON my_users.status = online{$current_user}.status
    INNER JOIN (SELECT user_id, COUNT(*) AS their_hours
    FROM online{$current_user}
    GROUP BY user_id) AS user_coef
    ON user_coef.user_id = my_users.user_id
    WHERE online{$current_user}.user_id = {$user}
    GROUP BY online{$current_user}.user_id, my_users.user_id, user_coef.their_hours
    ORDER BY hours_together DESC
    ) AS my_comp
    JOIN users{$current_user} ON (my_comp.user_id = id);
  2. Danyboy created this gist May 17, 2016.
    15 changes: 15 additions & 0 deletions compatibility.sql
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    SELECT id, link, name, hours_together, coef
    FROM (
    SELECT my_users.user_id, COUNT (*)::float / 12 AS hours_together, COUNT(*)::float / user_coef.their_hours AS coef
    FROM online{$current_user} LEFT JOIN online{$current_user} AS my_users
    ON my_users.status = online{$current_user}.status
    INNER JOIN (SELECT user_id, COUNT(*) AS their_hours
    FROM online{$current_user}
    GROUP BY user_id) AS user_coef
    ON user_coef.user_id = my_users.user_id
    WHERE online{$current_user}.user_id = {$user}
    GROUP BY online{$current_user}.user_id, my_users.user_id, user_coef.their_hours
    ORDER BY hours_together DESC
    ) AS my_comp
    JOIN users{$current_user}
    ON (my_comp.user_id = id);