about summary refs log tree commit diff
path: root/db/views/user_ips_v01.sql
blob: 50a8201cdfc7b6d25dce1284b6ea3967f60574da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
SELECT
  user_id,
  ip,
  max(used_at) AS used_at
FROM (
  SELECT
    id AS user_id,
    sign_up_ip AS ip,
    created_at AS used_at
  FROM users
  WHERE sign_up_ip IS NOT NULL
  UNION ALL
  SELECT
    user_id,
    ip,
    updated_at
  FROM session_activations
  UNION ALL
  SELECT
    user_id,
    ip,
    created_at
  FROM login_activities
  WHERE success = 't'
) AS t0
GROUP BY user_id, ip