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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:39:26+00:00 2026-05-28T13:39:26+00:00

I’m trying to write a plain SQL statement for building an Oracle report but

  • 0

I’m trying to write a plain SQL statement for building an Oracle report but I’m stuck at some point. x_request table stores the requests made and different tasks related to specific requests that have been done are stored in x_request_work_log. To summarize the structure of these tables:

X_request

-id  
-name
-requester
-request_date

x_request_work_log

-id
-request_id (foreign key)
-taskId
-start_date
-end_date

Now let’s assume that these tables are filled with sample data as follows:

x_request

id    name      requester    request_date
1     firstReq  John         01/01/2012
2     secondReq Steve        21/01/2012

x_request_work_log

id    requestId    taskId    startDate     endDate
1     1            0         01/01/2012    03/01/2012
2     1            1         04/01/2012    04/01/2012
3     1            2         05/01/2012    15/01/2012
4     2            0         24/01/2012    02/02/2012

The template of my report is as follows:

requestName    timeSpent(task(0))    timeSpent(task(1))     timeSpent(task(2)) 
|          |   |                 |   |                |     |                |

So, that’s where I’m stuck. I need a Sql Select statement that will return each row in the formatted way as described above. How can i retrieve and display the start and end dates of different tasks. Btw timeSpent = endDate(task(x)) – startDate(task(x))

Note: Using different select subqueries for each spent time calculation is not an option due to performance constraints. There must be another way.

  • 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-28T13:39:27+00:00Added an answer on May 28, 2026 at 1:39 pm

    It sounds like you just want something like

    SELECT r.name request_name,
           SUM( (CASE WHEN l.taskId = 0 
                      THEN l.endDate - l.StartDate
                      ELSE 0
                   END) ) task0_time_spent,
           SUM( (CASE WHEN l.taskId = 1 
                      THEN l.endDate - l.StartDate
                      ELSE 0
                   END) ) task1_time_spent,
           SUM( (CASE WHEN l.taskId = 2 
                      THEN l.endDate - l.StartDate
                      ELSE 0
                   END) ) task2_time_spent
      FROM x_request_work_log l
           JOIN x_request r ON (l.requestId = r.Id)
     GROUP BY r.name
    

    If you happen to be using 11g, you could also use the PIVOT operator.

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

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
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
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.