Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello fellow CPians,

I am trying to find average worker count between two given dates. I have the following query which gives me the desired days worker count.

For ex: The following gives me the worker count on 16.01.2014.

SQL
SELECT T.TOTALPERSCOUNT
FROM (
SELECT NVL(SUBSTR(p0.persid, 1, 2),'00') AS COMPANY,
    COUNT(*) AS TOPLAM
    FROM   pers0 p0, pers2 p2, role r
    WHERE p0.persid = p2.persid
        AND p2.client= r.client
        AND p2.persid= r.persid
        AND r.validfrom = (select max(validfrom) from role where client = p0.client and persid = p0.persid)
        AND p0.startdate < '16.01.2014'
        AND p0.leavedate >= '16.01.2014'
        AND p2.validfrom < '16.01.2014'
        AND p2.validuntil >= TO_DATE('16.01.2014', 'DD.MM.YYYY') -1
        AND p2.socinsurstat <> 7
    GROUP BY ROLLUP (SUBSTR (p0.persid, 1, 2))
    ORDER BY SUBSTR (p0.persid, 1, 2)
) T
WHERE T.COMPANY = '00'


I want to get an average worker count between dates 10.01.2014 and 15.02.2014. How can I accomplish this?

And here is the second query which gives me the dates between these given dates.
SQL
select to_date('10.01.2014','dd.MM.yyyy') + rownum -1 as DATEINTV
      from all_objects
     where rownum <=
to_date('15.02.2014','dd.MM.yyyy')-to_date('10.01.2014','dd.MM.yyyy')+1


I think some how I need to join these tables? Or maybe not?Maybe a different approach.

I will be using the result of this query in a C# project but I don't want to loop day by day if the interval is a year. Instead of making a 365 requests there should be a better effective way accomplishing this process in the database side.

Can someone help me sort this out. Thanks in advance.
Posted
Updated 25-Jul-14 0:28am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900