Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

444
Views
Promedio semanal que comienza en días diferentes - postgresql

Necesito calcular el promedio semanal de duración del uso de la aplicación (cada uso tiene su propio registro con la duración). El problema es que me gustaría comparar los promedios antes de que ocurriera un determinado evento y después (fecha diferente para cada usuario). Entonces, si el evento tuvo lugar el martes hace un mes, me gustaría calcular los promedios semanales a partir de los martes antes de ese martes específico y después.

Los datos relevantes son los siguientes: EVENTOS

 User ID || date of event 3fin2d..|| 19/03/17 2f4j34..|| 20/03/17

USO

 UID || timestamp start || timestamp end || Duration 3fin2d.. || 11/03/17 11:20:00 || 11/03/17 12:00:00 || 00:40 3fin2d.. || 18/03/17 11:20:00 || 18/03/17 12:00:00 || 00:40 2f4j34.. || 19/03/17 18:20:00 || 19/03/17 18:40:00 || 00:20 2f4j34.. || 19/03/17 19:20:00 || 19/03/17 20:00:00 || 00:40 3fin2d.. || 19/03/17 19:30:00 || 19/03/17 20:00:00 || 00:30 2f4j34.. || 20/03/17 19:20:00 || 20/03/17 20:00:00 || 00:40

editar: USUARIOS

 UID || Created On 3fin2d.. || 11/03/17 11:00:00 2f4j34.. || 18/03/17 13:00:00

Resultado Esperado:

 UID ||Average Duration before even||Average Duration After event 3fin2d.. || 00:40:00 || 00:30:00 2f4j34.. || 01:00:00 || 00:40:00

por supuesto, se deben considerar semanas con 0 uso. En el ejemplo anterior, asumo que la fecha actual es el 20/03/17 (de lo contrario, se deben contar muchos más ceros).

Gracias

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

http://rextester.com/USBJ20378

 select uid, avg(u.duration) filter (where usage_start < e.event_date) as before, avg(U.duration) filter (where usage_start >= e.event_date) as after from usage u inner join events e using (uid) where usage_start between e.event_date - 7 and e.event_date + 7 group by uid ; uid | before | after --------+----------+---------- 2f4j34 | 00:30:00 | 00:40:00 3fin2d | 00:40:00 | 00:30:00
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!