Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7171403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:24:28+00:00 2026-05-28T15:24:28+00:00

I have a query which I run on a table TXN_DEC(id, resourceid, usersid, date,

  • 0

I have a query which I run on a table TXN_DEC(id, resourceid, usersid, date, eventdesc) which return distinct count of users for a given date-range and resourceid, group by date and eventdesc (each resource can have 4 to 5 eventdesc)

if there is no value of distinct users count on a date in the range, for an eventdesc, then it skips that date row in the resultset.

I need to have all date rows in my resultset or collection such that if there is no value of count for a date,eventdesc combination, then its value is set to 0 but that date still exists in the collection..

How do I go about getting such a collection

I know getting the final dataset entirely from the query result would be too complicated,
but I can use collections in groovy to modify and populate my map/list to get the data in the required format

something similar to following: if

input date range = 5th Feb to 3 March 2011

      DataMap = [dateval: '02/05/2011' eventdesc: 'Read' dist_ucnt: 23,
                 dateval: '02/06/2011' eventdesc: 'Read' dist_ucnt: 23,
                 dateval: '02/07/2011' eventdesc: 'Read' dist_ucnt: 0,  -> this row was not present in query resultset, but row exists in the map with value 0
                 ....and so on till 3 march 2011 and then whole range repeated for each eventdesc
                     ] 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:24:29+00:00Added an answer on May 28, 2026 at 3:24 pm

    If you want all dates (including those with no entries in your TXN_DEC table) for a given range, you could use Oracle to generate your date range and then use an outer join to your existing query. Then you would just need to fill in null values. Something like:

    select 
        d.dateInRange as dateval,
        'Read' as eventdesc,
        nvl(td.dist_ucnt, 0) as dist_ucnt
    from (
        select 
            to_date('02-FEB-2011','dd-mon-yyyy') + rownum - 1 as dateInRange
        from all_objects
        where rownum <= to_date('03-MAR-2011','dd-mon-yyyy') - to_date('02-FEB-2011','dd-mon-yyyy') + 1
    ) d
    left join (
        select 
            date,
            count(distinct usersid) as dist_ucnt
        from
            txn_dec
        where eventDesc = 'Read'
        group by date 
    ) td on td.date = d.dateInRange
    

    That’s my purely Oracle solution since I’m not a Groovy guy (well, actually, I am a pretty groovy guy…)

    EDIT: Here’s the same version wrapped in a stored procedure. It should be easy to call if you know the API….

    create or replace procedure getDateRange (
        p_begin_date IN DATE, 
        p_end_date IN DATE, 
        p_event IN txn_dec.eventDesc%TYPE,
        p_recordset OUT SYS_REFCURSOR)
    AS
    BEGIN
        OPEN p_recordset FOR
        select 
            d.dateInRange as dateval,
            p_event as eventdesc,
            nvl(td.dist_ucnt, 0) as dist_ucnt
        from (
            select 
                p_begin_date + rownum - 1 as dateInRange
            from all_objects
            where rownum <= p_end_date - p_begin_date + 1
        ) d
        left join (
            select 
                date,
                count(distinct usersid) as dist_ucnt
            from
                txn_dec
            where eventDesc = p_event
            group by date 
        ) td on td.date = d.dateInRange;
    END getDateRange;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query which works fine in MySQL, but when I run it
I have a query which is meant to show me any rows in table
I have a query which searches two separate fields in the same table... looking
I have following complex query which I need to use. When I run it,
I have a query which takes a very long time to run but produces
SQL beginner here. I have a query which takes around 10 seconds to run,
OK I have this query which gives me DISTINCT product_series, plus all the other
I have a query which is crossing two tables select count(*) from ingenium.empevt, ingenium.evt
I have a mysql table like that and i need to run a query
I have a query, which when run from within phpMyAdmin, it works, however when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.