postgresql - Aggregate function with Date on Postgres -
I've rusted on my SQL in a way, maybe you can help me on this question.
Table Ticket
I have these two tables for a ticket system (I am leaving some fields):
(for foreign key, for foreign key) I inquire about closed tickets, and first message creation and final message creation In average the time spent between _date. This is what I have done so far: I am looking at some groups or total functions to get all the data from the table, and to calculate the time Trying to spend between the previous and the first, it is also trying to show the dates for the first and the last message. UPDATE I inserted an internal with another table instead of "OR", now I get both dates, and I can get the amount from my application: I think it did ... ID - built-in theme - text user_id - left off - boolean first_commission - large
SELECT t.id, t.subject, tm.creation_date Tickets from Tickets to TNI as ticket_messages TM on TM ID = T. First_memez or Tm.id = t.last_message WHERE t.closed = true
select t.id, t.subject, tm.creation_date, as tm.id = t.first_message ticket_messages on T interiors included as TM TM on interiors Tm2 form ticket_messages include ticket from tm2.creation_date. Id = t.last_message WHERE t.closed = true
In this way something like this should happen to get the NR of the day. You may need to easily put this in a subquery to exit more areas than 'Tickets'.
Select t.id, avg (tlast.creation_date - tfirst. Creation_date). T.F./T.:List_message on tlast as tm.id = t.first_message interstitial ticket_messages on tfirst as soon as ticket ticket is included in T. T..closed = true group by t.id
What may be the reason for joining (no test ..) eg
select from t.id, t.subject, sub.nr_days (t.id Select, AVG (tlast.creation_date - tfirst.creation_date) as tr intermediate ticket from T. Ticket to ticket_messages as tm.id = t.first_message Insider ticket_messages join in form tl.id = T.last_message ou tc Losed by t.id = true group) as soon as sub insertion ticket is included sub.id = t.id;
Comments
Post a Comment