Note that there are some explanatory texts on larger screens.

plurals
  1. POSQL to Find Number of Weeks an Employee Was Active Between Two Dates
    primarykey
    data
    text
    <p>I have a table with a list of dates where an employee became Active/Inactive and I want to count the weeks that an employee was Active within a certain date range.</p> <p>So the table (ps_job) would have values like this:</p> <pre><code>EMPLID EFFDT HR_STATUS ------ ----- ------ 1000 01-Jul-11 A 1000 01-Sep-11 I 1000 01-Jan-12 A 1000 01-Mar-12 I 1000 01-Sep-12 A </code></pre> <p>The query would need to show me the number of weeks that this emplid was active from 01-Jul-11 to 31-Dec-12.</p> <p>The desired result set would be:</p> <pre><code>EMPLID WEEKS_ACTIVE ------ ------------ 1000 35 </code></pre> <p>I got the number 35 by adding the results from the SQLs below:</p> <pre><code>SELECT (NEXT_DAY('01-Sep-11','SUNDAY') - NEXT_DAY('01-Jul-11','SUNDAY'))/7 WEEKS_ACTIVE FROM DUAL; SELECT (NEXT_DAY('01-Mar-12','SUNDAY') - NEXT_DAY('01-Jan-12','SUNDAY'))/7 WEEKS_ACTIVE FROM DUAL; SELECT (NEXT_DAY('31-Dec-12','SUNDAY') - NEXT_DAY('01-Sep-12','SUNDAY'))/7 WEEKS_ACTIVE FROM DUAL; </code></pre> <p></p> <p>The problem is I can't seem to figure out how to create a single query statement that will go through all the rows for every employee within a certain date range and just return each emplid and the number of weeks they were active. I would prefer to use basic SQL instead of PL/SQL so that I can transfer it to a PeopleSoft query that can be run by the user, but I am willing to run it for the user using Oracle SQL Developer if need be.</p> <p>Database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload