mysql - Fetching records from one table with different conditions -


hi working postgresql database. need calculate average time between records fetching 1 table.

schema:

create_table "user"  |t| t.text     "status" t.datetime "time" t.datetime "updated_at" 

end

example:

  1. select time users status = 'now';
  2. select time users status = 'after';

on results of above queries need perform average time. need combine 2 queries 1 query. tried union operator, whether right way use?. appreciated..

you should consider using sql select avg() function, each group. e.g.,

select status, avg(time)  users status = 'now' or status = 'after' group status 

Comments