简体   繁体   English

如何在 oracle-sql 中计算周一待处理票的总数?

[英]How to count total amount of pending tickets monday in oracle-sql?

I want to count the total amount of pending tickets for monday.我想计算星期一的待处理票的总数。 I don't want the amount of tickets that were moved to pending on monday but the total amount.我不想要周一被转移到待处理的门票数量,而是总数量。

table with sample data:带有样本数据的表:

在此处输入图像描述


Expected result:预期结果:
Total pending tickets monday周一待售票总数

If each row represents a ticket, then you can get the number that are pending on a particular day using:如果每一行代表一张票,那么您可以使用以下方法获取特定日期待处理的号码:

select count(*)
from t
where updated_at < :date and status = 'pending';

Note: This is not going to count "pending" statuses that were changed to another state.注意:这不会计算更改为另一个 state 的“待定”状态。 This data does not have enough information to answer that.该数据没有足够的信息来回答这个问题。 And your question has not explained the state changes.而且你的问题没有解释 state 的变化。

I would actually suggest that you ask a new question with more comprehensive information about what the states are, how they change as well as sample data and desired results.我实际上建议您提出一个问题,其中包含有关状态是什么、它们如何变化以及样本数据和期望结果的更全面的信息。

I am assuming that the tickets which are not closed are pending.我假设未关闭的票正在等待处理。 You can use the GROUP BY and HAVING as follows:您可以使用GROUP BYHAVING ,如下所示:

SELECT COUNT(1) AS PENDING FROM YOUR_TABLE T
 WHERE T.CREATED_AT <= <<YOUR_DATE>>
 GROUP BY T.TICKET_ID
HAVING SUM(CASE WHEN T.STATUS = 'closed' THEN 1 ELSE 0 END) = 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM