Jump to content

Sql query doubt


nikhilboorla

Recommended Posts

I have table like this
Ticket Date  |Total Tickets Created | Pending Tickets 
------------------------------------------------------
01-04-2021   |5000                  | 200 
02-04-2021   |2000                  | 100 
03-04-2021   |3000                  | 300 
   select t.created_date,t.source,t.ticket_type,
   count(*) as Total_Tickets_Created,
   sum(case when tch.before='Pending Credential' then 1 else 0 end) as Pending_Tickets,
        from r4e_mongo.mongo_repbiz_tickets t
        join r4e_mongo.mongo_repbiz_ticket_changelog tch on t.id=cast(tch.ticket_id as string) 

I want to get Pending Tickets Backlog until the previous day like below to create a report in google data studio with date filter.

Ticket Date  |Total Tickets Created | Pending Tickets | Pending Tickets Backlog
---------------------------------------------------------------------------------
01-04-2021   |5000                  | 200             |    1000
02-04-2021   |2000                  | 100             |    1100 --(1000+100)
03-04-2021   |3000                  | 300             |    1400 --(1100+300)

For example...i have selected October 15th date in report...it should show pending tickets backlog count until October 14

Link to comment
Share on other sites

  • nikhilboorla changed the title to Sql query doubt
3 hours ago, nikhilboorla said:
I have table like this

Ticket Date  |Total Tickets Created | Pending Tickets 
------------------------------------------------------
01-04-2021   |5000                  | 200 
02-04-2021   |2000                  | 100 
03-04-2021   |3000                  | 300 

   select t.created_date,t.source,t.ticket_type,
   count(*) as Total_Tickets_Created,
   sum(case when tch.before='Pending Credential' then 1 else 0 end) as Pending_Tickets,
        from r4e_mongo.mongo_repbiz_tickets t
        join r4e_mongo.mongo_repbiz_ticket_changelog tch on t.id=cast(tch.ticket_id as string) 

I want to get Pending Tickets Backlog until the previous day like below to create a report in google data studio with date filter.


Ticket Date  |Total Tickets Created | Pending Tickets | Pending Tickets Backlog
---------------------------------------------------------------------------------
01-04-2021   |5000                  | 200             |    1000
02-04-2021   |2000                  | 100             |    1100 --(1000+100)
03-04-2021   |3000                  | 300             |    1400 --(1100+300)

For example...i have selected October 15th date in report...it should show pending tickets backlog count until October 14

select ticket date, total_tickets_created,pending_tickets

,sum(pending_tickets) over(order by date) as pending_tickets_backlog

from mongo_repbiz_tickets

 

  • Like 1
  • Upvote 1
Link to comment
Share on other sites

8 hours ago, 8pm said:

select ticket date, total_tickets_created,pending_tickets

,sum(pending_tickets) over(order by date) as pending_tickets_backlog

from mongo_repbiz_tickets

 

worked..thanks..

Link to comment
Share on other sites

5 hours ago, 8pm said:

Aithe like kottu 

will it work for any date?

for ex. if i select oct 13th in date filter,it should show pending ticket count until oct 12..

Link to comment
Share on other sites

4 hours ago, nikhilboorla said:

will it work for any date?

for ex. if i select oct 13th in date filter,it should show pending ticket count until oct 12..

Adhi running sum it keeps on adding that’s it.

now you have to chose filters wisely

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...