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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:32:15+00:00 2026-05-10T18:32:15+00:00

Hopefully I can do the problem justice, because it was too difficult to summarise

  • 0

Hopefully I can do the problem justice, because it was too difficult to summarise it in the title! (suggestions are welcome in the comments)

Right, so here’s my table:

Tasks   task_id        (number)   job_id         (number)   to_do_by_date  (date)   task_name      (varchar / text)   status         (number)   completed_date (date) 

for arguments sake let’s make the values of status:

1 = New 2 = InProgress 3 = Done 

and what I’m having trouble trying to do is create a query that pulls back all of the tasks:

  • where any of the tasks for a job_id have a status <> Done
    • except where all tasks for a job_id are are done, but one or more tasks have a completed_date of today
  • ordered by the to_be_done_by date, but grouping all of the job_id tasks together
    • so the job_id with the next `to_do_by_date’ task is shown first

some information about the data:

  • a job_id can have an arbitrary number of tasks

Here’s an example of the output I’m trying to get:

task_id   job_id   to_do_by_date   task_name   status   completed_date    1        1        yesterday        -          3        yesterday    2        1        today            -          3        today    3        2        now              -          3        today    4        2        2 hours time     -          2        {null}    5        2        4 hours time     -          2        {null}    6        2        tomorrow         -          1        {null}    7        3        3 hours time     -          2        {null}    8        3        tomorrow         -          1        {null}    9        3        tomorrow         -          1        {null} 

I’m using Oracle 10g, so answers for Oracle or ANSI SQL, or a hint for how to approach this would be ideal, and I can create Views or wrap this in a Stored Procedure to offload logic from the application if your solution calls for it.

here’s a sql script that will create the example test data shown above:

create table tasks (task_id number, job_id number, to_do_by_date date, task_name varchar2(50), status number, completed_date date); insert into tasks values (0,0,sysdate -2,    'Job 0, Task 1 - dont return!', 3, sysdate -2); insert into tasks values (1,1,sysdate -1,    'Job 1, Task 1', 3, sysdate -1); insert into tasks values (2,1,sysdate -2/24, 'Job 1, Task 2', 3, sysdate -2/24); insert into tasks values (3,2,sysdate,       'Job 2, Task 1', 3, sysdate); insert into tasks values (4,2,sysdate +2/24, 'Job 2, Task 2', 2, null); insert into tasks values (5,2,sysdate +4/24, 'Job 2, Task 3', 2, null); insert into tasks values (6,2,sysdate +1,    'Job 2, Task 4', 1, null); insert into tasks values (7,3,sysdate +3/24, 'Job 3, Task 1', 2, null); insert into tasks values (8,3,sysdate +1,    'Job 3, Task 2', 1, null); insert into tasks values (9,3,sysdate +1,    'Job 3, Task 3', 1, null); commit; 

Many, many thanks for your help :o)

  • 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. 2026-05-10T18:32:15+00:00Added an answer on May 10, 2026 at 6:32 pm

    Obviously you will have to fix this up a bit but I hope you get the idea.

    SELECT      task_id, job_id, to_do_by_date, task_name, status, completed_date FROM     Tasks WHERE     job_id IN (         SELECT job_id          FROM Tasks          WHERE status <> 'Done'          GROUP BY job_id)     OR     job_id IN (         SELECT job_id          FROM Tasks          WHERE status = 'Done' AND completed_date = 'Today'             AND job_id NOT IN (SELECT job_id FROM Tasks WHERE status <> 'Done' GROUP BY job_id)         GROUP BY job_id) ORDER BY     job_id, to_do_by_date 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to WPF and data binding so hopefully I can explain the problem
I have a weird date rounding problem that hopefully someone can solve. My client
Hopefully someone can help me with this problem. I'm starting to work with Drupal
Hopefully someone can help me debug this problem as EXC_BAD_ACCESS is the only error
Let me explain my problem, and hopefully someone can offer some good advice. I
Hopefully someone can shed a little light on an issue that I'm currently having
First shot at throwing a question on these boards so hopefully I can get
Slightly strange question, but hopefully someone can help. In essence, if the time was
Ok, this is bit of an obscure question, but hopefully someone can help me
Hopefully some Custom Control Designers/Builders can help I'm attempting to build my first custom

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.