Q
Problem solve Get help with specific problems with your technologies, process and projects.

# Grouping rows by 5-30 days, 31-60 days, and 61-90 days

I am trying to query a table and find tickets that are open between 5-30 days, 31-60 days and 61-90 days. I want all three queries in one report, and I would like them totalled at the bottom.

My query so far is

```select tableone.group "Assigned "
, tabletwo.ticket "Ticket "
, tabletwo.datecreated "Date "
from tableone
, tabletwo
where tableone.status = 'Open'
and tabletwo.assigned = tableone.person
and trunc(tabletwo.datecreated)
<= trunc(sysdate-5)
and trunc(tabletwo.datecreated)
>= trunc(sysdate-30)```

My question is (and this may be easy but I'm not sure where to start to look) how do I get the query to pull the data for the 31-60 days and the 61-90 days?

At this point, my output shows:

```Assigned  Ticket  Date
Sales      3241  05/31/2002```

I would like the report to group the tickets for 5-30 days, then group for 31-60, and then for 61-90. I've tried different things, but obviously not the right one. Thanks for any help....

I'm not sure your TRUNC technique is the right way to do date comparisons. I'm assuming this is Oracle. Doesn't TRUNC on a date field return a string? You're going to have problems when you're looking for 90-day tickets, because the standard Oracle date formats like '21-JUN-02' include month abbreviations that just don't collate properly. To say nothing about year boundaries.

When Oracle does date calculations on ordinary DATE columns, the results are always given in days, which is perfect for your requirements.

Try the following --

```select case
when sysdate - tabletwo.datecreated
between  5 and 30
then ' 5-30'
when sysdate - tabletwo.datecreated
between 31 and 60
then '31-60'
when sysdate - tabletwo.datecreated
between 61 and 90
then '61-90'
end as agegroup
, tableone.group "Assigned "
, tabletwo.ticket "Ticket "
, tabletwo.datecreated "Date "
from tableone
, tabletwo
where tableone.status = 'Open'
and tabletwo.assigned = tableone.person
and sysdate - tabletwo.datecreated
between 5 and 90
order by agegroup```

To get totals for all, just repeat the query with 'ZZZZZ' instead of the CASE construct (so that it sorts last) and run both queries together as subselects in a UNION ALL.

## SearchDataManagement

• ### Who belongs on a high-performance data governance team?

Putting together a high-quality data governance team can be a challenge. Explore the necessary team members and best practices ...

• ### Soda launches cloud service to improve data observability

Data quality vendor Soda has had a busy 2021, building out new services and raising funding to help organizations identify and ...

• ### Bigeye raises \$17M Series A funding to boost data quality

Former Uber exec, CEO and co-founder of a startup, outlines the challenges and opportunities of enabling a new data trust ...

## SearchBusinessAnalytics

• ### Insightsoftware acquisition of Izenda targets embedded BI

ERP vendor Insightsoftware acquired embedded analytics specialist Izenda on April 15, marking its second purchase of an embedded ...

• ### Data scientist shortage leaves organizations uncertain

Despite their desire to use data science in their decision-making process, some organizations can't find qualified data ...

• ### Air Force's data overhaul makes analytics a priority

With its data locked in legacy systems that didn't communicate with one another, in 2017 the Air Force started to overhaul of its...

## SearchSAP

• ### S/4HANA Cloud SaaS ERP: Buying team overview

SAP's multi-tenant SaaS ERP, S/4HANA Cloud, is a viable choice for companies that need ease in their infrastructure management. ...

• ### SAP forms financial services partnership with Dediq

SAP and financial industry investment firm Dediq are forming a new business unit to develop applications that help banks and ...

• ### Unpatched applications threaten SAP security

Cyberattacks are a significant threat to unpatched, unprotected SAP applications, according to a new threat intelligence report ...

## SearchSQLServer

• ### SQL Server database design best practices and tips for DBAs

Good database design is a must to meet processing needs in SQL Server systems. In a webinar, consultant Koen Verbeeck offered ...

• ### SQL Server in Azure database choices and what they offer users

SQL Server databases can be moved to the Azure cloud in several different ways. Here's what you'll get from each of the options ...

• ### Using a LEFT OUTER JOIN vs. RIGHT OUTER JOIN in SQL

In this book excerpt, you'll learn LEFT OUTER JOIN vs. RIGHT OUTER JOIN techniques and find various examples for creating SQL ...

## TheServerSide.com

• ### Incorporate diversity and inclusion in technology design

DEI in technology is about more than creating a diverse workplace. We talked to a few DEI professionals about how teams build ...

• ### Microsoft previews OpenJDK distro to the delight of devs

In a move meant to attract more Java developers to its Azure cloud and further support the Java community, Microsoft launched a ...

• ### Supreme Court ruling on Java APIs eases developer worries

Now that the Supreme Court has ruled for Google over Oracle in their high-stakes copyright battle over Java APIs, developers can ...

## SearchDataCenter

• ### Programmable processor technology for next-gen data centers

The right processing technology can benefit your data center. Learn about advancements in CPU technologies, recent vendor ...

• ### Data processing units accelerate infrastructure performance

DPUs often run on networking packets to move information in the data center, instead of supporting processing workflows. Get an ...

• ### New Intel Ice Lake processors boost performance, security

Intel launches third-generation Xeon Scalable processors that bolster security, accelerate common data center workloads by 46% on...

## SearchContentManagement

• ### OpenText releases Cloud Editions content services updates

OpenText CE 21.2 includes federated document compliance that extends to Microsoft Office 365, along with a revamped content ...

• ### Adobe courts small businesses with Acrobat Pro package

As the pandemic disrupts paper workflows, Adobe courts small business users with simple webforms, digital signatures and payments...

• ### Know when to use a headless CMS and when it's not worth it

Headless CMSes aren't a silver bullet for every circumstance. Evaluate three solid use cases for a headless CMS and three ...

## SearchHRSoftware

• ### DEI tools arrive at critical time for HR

Employers are being held accountable for meeting diversity, equity and inclusion goals, especially executives. HR vendors are ...

• ### Oracle Cloud HCM introduces low-code/no-code template tools

Oracle Cloud HCM has been upgraded to ease development of HR processes and improve employee experience, the firm said.

• ### Hybrid workplace may give employers hiring edge

The post-pandemic office is leaning strongly in the direction of hybrid workplaces. Job candidates view working from home as a ...

Close