Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT st.user_id,
- to_json(max(case when id=maxid then properties->'assumed_gender' end)) AS assumed_gender,
- to_json(max(case when id=maxid then properties->'email' end)) AS email,
- to_json(max(case when id=maxid then properties->'first_name' end)) AS first_name,
- to_json(max(case when id=maxid then properties->'last_name' end)) AS last_name,
- to_json(max(case when id=maxid then properties->'country_name' end)) AS country_name,
- to_json(max(case when id=maxid then properties->'city_name' end)) AS city_name,
- to_json(max(case when id=maxid then properties->'mobile_number' end)) AS mobile_number,
- json_agg(to_json(properties->'submission_url')) AS submission_urls
- FROM daily_statistics st JOIN (
- SELECT u.id as user_id, (
- SELECT st2.id FROM daily_statistics st2 WHERE st2.user_id=u.id
- ORDER BY st2.id DESC LIMIT 1) AS maxid FROM users u
- )
- mu ON (st.user_id=mu.user_id)
- GROUP BY st.user_id;
- DailyStatistic.select("
- daily_statistics.user_id,
- to_json(max(case when id=maxid then properties->'following' end)),
- to_json(max(case when id=maxid then properties->'assumed_gender' end)),
- to_json(max(case when id=maxid then properties->'email' end)),
- to_json(max(case when id=maxid then properties->'first_name' end)),
- to_json(max(case when id=maxid then properties->'last_name' end)),
- to_json(max(case when id=maxid then properties->'country_name' end)),
- to_json(max(case when id=maxid then properties->'city_name' end)),
- to_json(max(case when id=maxid then properties->'mobile_number' end)),
- json_agg(to_json(properties->'submission_url'))
- ").join("
- JOIN(
- SELECT u.id as user_id, (
- SELECT st2.id FROM daily_statistics st2 WHERE st2.user_id=u.id
- ORDER BY st2.id DESC LIMIT 1) AS maxid FROM users u
- )
- mu ON (daily_statistics.user_id=mu.user_id)
- ").group("daily_statistics.user_id")
- PG::UndefinedColumn: ERROR: column "maxid" does not exist
- LINE 1: ...aily_statistics.user_id, to_json(max(case when id=maxid then...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement