自上次帮助故障单上的天数被提起

时间:2015-12-22 14:45:06

标签: sql amazon-redshift domo

我正在尝试创建一份报告,向我显示客户提交票证的最后日期。

客户可以提交数十张门票。我想知道最后一张票的提交时间,并显示自从他们这样做了多少天。

我拥有的字段是:

客户,

Ticket_id,

Date_Closed

所有来自同一张表“门票”

我想我想在最后约会时对门票进行排名?我尝试了这个查询来获取一些东西,但它给了我所有客户的门票。 (我在名为Domo的产品中使用SQL)

select * from (select *, rank() over (partition by "Ticket_id" 
                order by "Date_Closed" desc) as date_order
from tickets ) zd
where date_order = 1

4 个答案:

答案 0 :(得分:2)

这应该很简单,

Runnable

答案 1 :(得分:1)

select Customer, datediff(day, date_closed, current_date) as days_since_last_tkt
from 
(select *, rank() over (partition by Customer order by "Date_Closed" desc) as date_order
from tickets) zd
join tickets t on zd.date_closed = t.date_closed
where zd.date_order = 1

或者你可以简单地做

select customer, datediff(day, max(Date_closed), current_date) as days_since_last_tkt
from tickets
group by customer

选择其他字段

select t.* 
from tickets t
join (select customer, max(Date_closed) as mxdate,
      datediff(day, max(Date_closed), current_date) as days_since_last_tkt
      from tickets
      group by customer) tt 
on t.customer = tt.customer and tt.mxdate = t.date_closed

答案 2 :(得分:0)

我会用一个简单的子查询来选择客户的最后一个截止日期。然后将此与今天Select LastTicket.Customer, LastTicket.LastClosedDate, DateDiff(day,LastTicket.LastClosedDate,getdate()) as DaysSinceLastClosed From (select tickets.customer max(tickets.dateClosed) as LastClosedDate from tickets Group By tickets.Customer) as LastTicket 进行比较,以获得自上次关闭以来的天数。

var myTask = new Task(...
myTask.Tag("The name here");
var nameOfTask = (string)myTask.Tag();

答案 3 :(得分:0)

根据回复,这就是我所做的:

select "Customer",
Max("date_closed") "last_date,

round(datediff(DAY, CURRENT_DATE, max("date_closed")), 0) as "Closed_date"

from tickets

group by "Customer"
ORDER BY "Customer"