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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:14:26+00:00 2026-06-12T23:14:26+00:00

I’m stuck with a seemingly easy query, but couldn’t manage to get it working

  • 0

I’m stuck with a seemingly easy query, but couldn’t manage to get it working the last hours.

I have a table files that holds file names and some values like records in this file, DATE of creation (create_date), DATE of processing (processing_date) and so on. There can be multiple files for a create date in different hours and it is likely that they will not get processed in the same day of creaton, in fact it can even take up to three days or longer for them to get processed.

So let’s assume I have these rows, as an example:

create_date            | processing_date
------------------------------
2012-09-10 11:10:55.0  | 2012-09-11 18:00:18.0
2012-09-10 15:20:18.0  | 2012-09-11 13:38:19.0
2012-09-10 19:30:48.0  | 2012-09-12 10:59:00.0
2012-09-11 08:19:11.0  | 2012-09-11 18:14:44.0
2012-09-11 22:31:42.0  | 2012-09-21 03:51:09.0

What I want in a single query is to get a grouped column truncated to the day create_date with 11 additional columns for the differences between the processing_date and the create_date, so that the result should roughly look like this:

create_date   |   diff0days   | diff1days | diff2days | ... | diff10days
------------------------------------------------------------------------
2012-09-10    |       0             2           1       ...        0
2012-09-11    |       1             0           0       ...        1

and so on, I hope you get the point 🙂

I have tried this and so far it works getting a single aggregated column for a create_date with a difference of – for example – 3:

SELECT TRUNC(f.create_date, 'DD') as created, count(1) FROM files f WHERE TRUNC(f.process_date, 'DD') - trunc(f.create_date, 'DD') = 3 GROUP BY TRUNC(f.create_date, 'DD')

I tried combining the single queries and I tried sub-queries, but that didn’t help or at least my knowledge about SQL is not sufficient.

What I need is a hint so that I can include the various differences as columns, like shown above. How could I possibly achieve this?

  • 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-06-12T23:14:27+00:00Added an answer on June 12, 2026 at 11:14 pm

    That’s basically the pivoting problem:

    SELECT  TRUNC(f.create_date, 'DD') as created
    ,       sum(case TRUNC(f.process_date, 'DD') - trunc(f.create_date, 'DD')
                      when 0 then 1 end) as diff0days   
    ,       sum(case TRUNC(f.process_date, 'DD') - trunc(f.create_date, 'DD')
                      when 1 then 1 end) as diff1days   
    ,       sum(case TRUNC(f.process_date, 'DD') - trunc(f.create_date, 'DD')
                      when 2 then 1 end) as diff2days   
    ,       ...
    FROM    files f 
    GROUP BY 
            TRUNC(f.create_date, 'DD')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have thousands of HTML files to process using Groovy/Java and I need to
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.