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 3219388
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T15:38:23+00:00 2026-05-17T15:38:23+00:00

I am trying to group my data based on age. I use the following

  • 0

I am trying to group my data based on age. I use the following database select:

select * from (
select 0 range_start, 11 range_end, '0-10 days' date_description from dual union
select 11, 21, '11-20 days' from dual union  
select 21, 31, '21-30 days' from dual union  
select 31, 99999, '31+ days' from dual) date_helper
left outer join table
on table.date <= date_helper.range_start*-1 + sysdate 
and table.date > date_helper.range_end*-1 + sysdate 

I then make a group based on the date_description column. I am trying to make it display all groups, even when there are no records, that fall within that group.
If there are no records, I want it to have a value of 0, and still print the group.

  • 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-17T15:38:24+00:00Added an answer on May 17, 2026 at 3:38 pm

    Expanding on a comment on PowerUser’s answer, if you’re using a version of Crystal that allows you to enter your own SQL (instead of having to use Crystal’s Database Expert), you can set up a subquery that acts as a helper table – something like:

    select * from (
    select 0 range_start, 11 range_end, '0-10 days' date_description from dual union
    select 11, 21, '11-20 days' from dual union  
    select 21, 31, '21-30 days' from dual union  
    select 31, 99999, '31+ days' from dual) date_helper
    left outer join 
    (select sysdate-5 mydate from dual union all 
     select sysdate - 25 from dual) mytable
    on mytable.mydate <= date_helper.range_start*-1 + sysdate 
    and mytable.mydate > date_helper.range_end*-1 + sysdate 
    

    (Oracle syntax – the precise syntax of the query will vary depending on which dialect of SQL you are using.)

    EDIT: Changed from SQLServer to Oracle syntax.

    FURTHER EDIT: Added some simple sample data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to group a set of data based on the range of an
My group is developing a service-based (.NET WCF) application and we're trying to decide
I am trying to save data into the same table several times from the
I am trying to group a number of customers together based on their Head
I am trying to extract duplicate rows from my database. I have a listings
I'm trying to pull values from a database for a web app where a
I am trying to pull some data out of our testing database with an
I'm trying to reorder/group a set of results using SQL. I have a few
Trying to figure out an equation to get the current group a page would
I'm trying to set the group type for a new Active Directory Entry via

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.