SHARE
TWEET

Untitled

a guest Nov 12th, 2019 85 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     -- ES Tienen entrenamientos    
  2.   INSERT INTO weekly_impact_calculations
  3.        (athlete_id, date_snap, year_snap, week_of_year_snap, date_from, date_until,
  4.  first_name, utc_time, language, language_es, has_selected_cause,
  5.  has_impact,
  6.  has_pending_donations,
  7.  has_goal, progress,
  8.  workouts, workouts_text,
  9.  donated_calories, donated_calories_text,
  10.  steps, steps_text,
  11.  donation_title, -- "Donaciones / Donations"
  12.  donations_value, donations_value_text,
  13.   points_earned, points_earned_text,
  14.  used_points, used_points_text,
  15.  available_points, available_points_text)
  16.  
  17.  
  18. --          workouts, calories, meals, meals_real, workouts_text, calories_text, meals_text)  
  19.  
  20. --    SELECT t.athlete_id, _date_snap, _year_snap, _week_of_year_snap, _date_from, _date_until,  
  21. SELECT a.id, now(), 2019, 45, (now() - interval '1 week')::date, now()::date,
  22. -- SELECT a.id,
  23.             u.first_name, a.utc_time, a.language, CASE WHEN a.language = 'es' OR a.language IS NULL THEN 1 ELSE 0 END, 1,
  24.             CASE WHEN COUNT(v.id) > 0 THEN 1 ELSE 0 END,
  25.             CASE WHEN COUNT(v.id) > COUNT(v.donation_id) THEN 1 ELSE 0 END,
  26.             CASE WHEN mma.goal > 0 THEN 1 ELSE 0 END, mma.advance_percentage,
  27.             COUNT(v.training_start_date), to_char(COUNT(v.training_start_date),'99999999'),
  28.             SUM(d.donated_calories), to_char(SUM(d.donated_calories),'99999999'),
  29.             SUM(v.steps_steps), to_char(SUM(steps_steps),'99999999'),
  30.             CASE WHEN a.language = 'es' OR a.language IS NULL THEN 'Donaciones' ELSE 'Donations' END,
  31.             SUM(d.donated_value), to_char(SUM(d.donated_value),'99999999'),
  32.             SUM(CASE WHEN p.btg_points > 0 THEN p.btg_points ELSE 0 END), to_char(SUM(CASE WHEN p.btg_points > 0 THEN p.btg_points ELSE 0 END),'99999999'),
  33.             SUM(CASE WHEN p.btg_points < 0 THEN p.btg_points ELSE 0 END), to_char(SUM(CASE WHEN p.btg_points < 0 THEN p.btg_points ELSE 0 END),'99999999'),
  34.             a.available_btg_points, to_char(a.available_btg_points,'99999999')
  35.   FROM view_materialized_activities_all v
  36.     INNER JOIN burn_to_give_athlete a ON (v.athlete_id = a.id)
  37.     INNER JOIN auth_user u ON (a.user_id = u.id)
  38.     LEFT JOIN burn_to_give_metricsmonthathlete mma ON (v.athlete_id = mma.athlete_id)
  39.     LEFT JOIN burn_to_give_donation d ON (v.donation_id = d.id)  
  40.     LEFT JOIN burn_to_give_btgpoints p ON (v.athlete_id = p.athlete_id)
  41.     --LEFT JOIN burn_to_give_athletebycampaign abc (a.id = abc.id)
  42.  WHERE a.id = 236 AND
  43.  v.date BETWEEN now() - interval '1 month' AND now()
  44.  AND p.date BETWEEN now() - interval '1 month' AND now()
  45.  AND EXTRACT(YEAR FROM mma.date) = EXTRACT(YEAR FROM now()) AND EXTRACT(MONTH FROM mma.date) = EXTRACT(MONTH FROM now())
  46.  AND mma.advance_percentage > 0 -- BORRAR ESTO ES DE PRUEBAAAA
  47. GROUP BY  a.id, u.first_name, a.utc_time, a.language, mma.goal, mma.advance_percentage
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top