Date rage count

HI
Need some help in this SQL
WITH EMP_TAB AS(
SELECT 1 EMPID, to_date('30-Mar-2011','dd-MON-yyyy') D from dual union all
SELECT 1 EMPID, to_date('24-Mar-2011','dd-MON-yyyy') D from dual union all
SELECT 1 EMPID, to_date('23-Mar-2011','dd-MON-yyyy') D from dual union all
SELECT 1 EMPID, to_date('22-Mar-2011','dd-MON-yyyy') D from dual union all
SELECT 1 EMPID, to_date('20-Mar-2011','dd-MON-yyyy') D from dual union all
SELECT 1 EMPID, to_date('18-Mar-2011','dd-MON-yyyy') D from dual union all
SELECT 3 EMPID, to_date('17-Mar-2011','dd-MON-yyyy') D from dual
) SELECT * FROM EMP_TAB;here in this table When I pass parameter as empid=1 and D as '25-Mar-2011' The query should check the number of continuous dates starting from 24-Mar-2011
So the result should return, as we have 3 dates from 24th to 22nd
EMPID RANGE
1        3Edited by: Prasath on 29-Mar-2011 07:07

Hi SY.
The one with analytical function doesnt work if you have duplicate dates.
SQL> WITH EMP_TAB AS(
  2                  SELECT 1 EMPID, TO_DATE('30-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  3                  SELECT 1 EMPID, TO_DATE('24-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  4                  SELECT 1 EMPID, TO_DATE('22-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  5                  SELECT 1 EMPID, TO_DATE('22-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  6                  SELECT 1 EMPID, TO_DATE('20-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  7                  SELECT 1 EMPID, TO_DATE('18-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  8                  SELECT 3 EMPID, TO_DATE('17-Mar-2011','dd-MON-yyyy') D FROM dual
  9                 )
10  SELECT 1 EMPID, MAX (RN)
11    FROM (SELECT D, ROW_NUMBER () OVER (ORDER BY D DESC) RN
12            FROM EMP_TAB
13           WHERE EMPID = 1
14             AND D < DATE '2011-03-25')
15   WHERE D = DATE '2011-03-25' - RN;
     EMPID    MAX(RN)
         1          3
SQL>
The result should be 1.. but got 3.
Dense rank should work
SQL> WITH EMP_TAB AS(
  2                  SELECT 1 EMPID, TO_DATE('30-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  3                  SELECT 1 EMPID, TO_DATE('24-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  4                  SELECT 1 EMPID, TO_DATE('22-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  5                  SELECT 1 EMPID, TO_DATE('22-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  6                  SELECT 1 EMPID, TO_DATE('20-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  7                  SELECT 1 EMPID, TO_DATE('18-Mar-2011','dd-MON-yyyy') D FROM dual UNION ALL
  8                  SELECT 3 EMPID, TO_DATE('17-Mar-2011','dd-MON-yyyy') D FROM dual
  9                 )
10  SELECT 1 EMPID, MAX (RN)
11    FROM (SELECT D, DENSE_RANK () OVER (ORDER BY D DESC) RN
12            FROM EMP_TAB
13           WHERE EMPID = 1
14             AND D < DATE '2011-03-25')
15   WHERE D = DATE '2011-03-25' - RN;
     EMPID    MAX(RN)
         1          1
SQL> G.

Similar Messages

  • How to Plot number and string in one row (data logger counter) ?

    hi all i made data log quantity using Digital Counter via modbus to monitoring quantity and reject that has and Name Operator, Machine and Part Number.
    i have problem about plot the number & string in one row, as shown on the picture below :
    how to move that string on one row ? i attach my vi.
    Thanks~
    Attachments:
    MODBUS LIB Counter.vi ‏39 KB

    Duplicate and answered - http://forums.ni.com/t5/LabVIEW/How-to-Plot-number-and-string-in-one-row-data-logger-counter-via/m-p...

  • What has caused "data error count"  under execution detail on Audit browser

    Hi,
    I have a simple mapping that load data from external table to target fact table. From OWB Runtime Audit browser, the Execution Details page show the status= Complete + <Red error sign>. And the value under Data error count is 2563. Where can I look for information about what has caused this errors or what the data error are? The SQL*Loader log file looks OK and no bad file generated. And I don't see suspecious under WB_RT_AUDIT*, WB_RT_ERROR tables It's owb9ir2 on 9iDB Thanks.

    Solved. I set the audit level to the highest and re-executed and can see the error msg now. It would be nice if audit broser can show the report for all the rejected rows.

  • Last Skipped Date, Skip count, are not updated in any songs that i listen in my iPhone5s

    I've been using smart playlist that's relays on the play count, last skipped date and skipped count fields... I have been using an old ipod to heard my music through this smart playlist that live updates all the time and it was working great.
    So my issue is, since i bought a new iPhone 5S and start using it to listen music, my smart playlist that relays on " play count, last skipped date, skipped count " fields are not updating, and when i connect my iphone to the PC i realize that those fields never update after i play or skip any song in my iPhone.
    So, I'm not sure if this is an iPhone restriction, that i need to use my iPod again to get my smart playlist that relys on those fields to work... or my iphone is defective and need to re-install the iOS.
    Any help on this matter will be enormously appreciated
    Thanks in advance

    I have playlists that rely on the Last Skipped and
    Skip Count properties of songs, but these items only
    seem to be triggered if the song is fast forwarded
    between 3-20 seconds into the song. I tried to skip
    I think this is how it's intended, though there isn't much info on this feature. I've seen the same behavior and other users have reported same.
    One thing that threw me off for a bit using this feature was trying to use with playlists where the songs had "remember playback position" checked. Last skipped doesn't register at all with these tracks.

  • Cisco UCCX 10.6 Get XML Document Data XPath count() function

    Hi
    I'd like to retrieve the number of XML nodes in a document to make a script more efficient.
    e.g. with this XML, I'd like to know how many <message> nodes there are:
    <messages>
    <message>contentA</message>
    <message>contentA</message>
    <message>contentA</message>
    </messages>
    I've tried iNodeCount = Get XML Document Data (inputXMLfile, "count(//messages/message)")
    If I try this in an XPath expression tester then I get the result I'm expecting - an integer of 3. However, in UCCX this produces the error "Can not convert #NUMBER to a NodeList!"... What am I doing wrong?
    Thanks

    Hi, 
    you may want to use a Set or a Do step to execute Java code. 
    First, reference the XML file (within the repository) by calling DOC[myFile.xml] and of course, assigning this value to a Document type variable, e.g.: 
    Set myDocument = DOC[myFile.xml]
    Then add a Do step that actually does the XPath part of the job. 
    There's a nice step by step explanation of it here: http://viralpatel.net/blogs/java-xml-xpath-tutorial-parse-xml/
    Remember, you can get the Inputstream object of the myDocument variable using the getInputStream() method on it.
    G.

  • How to Plot number and string in one row (data logger counter via MODBUS) ?

    hi all i made data log quantity using Digital Counter via modbus (RS-485) to monitoring quantity and reject that has and Name Operator, Machine and Part Number.
    i have problem about plot the number & string in one row, as shown on the picture below :
    how to move that string on one row ? i attach my vi.
    Thanks~
    Solved!
    Go to Solution.
    Attachments:
    MODBUS LIB Counter.vi ‏39 KB

    Hi rhiesnand,
    right now you add 2 new rows to your array.
    The solution is to concatenate both row parts to one bigger 1D array before adding that array as new row to your 2D array!
    Like this:
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • Data usage counter

    My provider is Bell in Ontario, Canada.
    10 days into my billing cycle I noticed that this month the "unbilled" data usage as tracked by my provide is significantly less (about 100 MB or so) than the data usage tracked by the phone itself in the Settings area. Is this normal?

    To ask the most obvious first, did you reset the usage counter at the start of your billing cycle? Or is it showing usage from the previous cycle?
    Next, some providers have delays in their usage reporting. AT&T's delay is only a few hours, but I don't know about Bell Canada.

  • Union dates and count(*) from different tables

    Hope you can help. Using Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    I have tables called apples, oranges, and pears. I want to get a count of all apples, oranges, pears and a total for a date range in one query statement. Any ideas?
    for apples the sql is select count(apple_types) from apples where apple_date > TO_DATE('2012-01-01')
    for oranges the sql is select count(orange_types) from orange where orange_date > TO_DATE('2012-01-01')
    for pears the sql is s elect count(pear_types) from pears where pears_date > TO_DATE('2012-01-01')
    EXAMPLE DATA
    Data for apples
    2012-01-01 4
    2012-04-23 1
    Data for oranges
    2012-02-13 5
    2012-03-11 2
    Data for pears
    2012-01-01 11
    I would like the output to be
    date count(apple_types) count(orange_types) count(pear_types) total
    2012-01-01 4 0 11 15
    2012-02-13 0 5 0 5
    2012-03-11 0 2 0 2
    2012-04-23 1 0 0 1

    here is one with pivot
    WITH apples
         AS (SELECT TO_DATE ('2012-01-01', 'yyyy-mm-dd') dt, 4 cnt FROM DUAL
             UNION ALL
             SELECT TO_DATE ('2012-04-23', 'yyyy-mm-dd') dt, 1 cnt FROM DUAL),
         oranges
         AS (SELECT TO_DATE ('2012-01-13', 'yyyy-mm-dd') dt, 5 cnt FROM DUAL
             UNION ALL
             SELECT TO_DATE ('2012-03-11', 'yyyy-mm-dd') dt, 2 cnt FROM DUAL),
         pears
         AS (SELECT TO_DATE ('2012-01-01', 'yyyy-mm-dd') dt, 11 cnt FROM DUAL),
         t
         AS (  SELECT dt, SUM (cnt) cnt, 'apples' fruit
                 FROM apples
             GROUP BY dt
             UNION ALL
               SELECT dt, SUM (cnt), 'oranges'
                 FROM oranges
             GROUP BY dt
             UNION ALL
               SELECT dt, SUM (cnt), 'pears'
                 FROM pears
             GROUP BY dt)
      SELECT dt,
             NVL (apples, 0),
             NVL (oranges, 0),
             NVL (pears, 0),
             NVL (apples, 0) + NVL (oranges, 0) + NVL (pears, 0) total
        FROM t PIVOT (MAX (cnt)
               FOR fruit
               IN ('apples' AS apples, 'oranges' AS oranges, 'pears' AS pears))
    ORDER BY 1
    DT     NVL(APPLES,0)     NVL(ORANGES,0)     NVL(PEARS,0)     TOTAL
    1/1/2012     4     0     11     15
    1/13/2012     0     5     0     5
    3/11/2012     0     2     0     2
    4/23/2012     1     0     0     1

  • Given various date ranges, count the occurrences of dates in PL/SQL

    i have a table of employees that have a start date and end date on a project. Some employees end date is null because they are still working on the project. So I want to find for each day in JAN, how many people on working on the project.
    So I generate the dates JAN 1 - 31 with this:
    Declare
      days DATE := To_Date('01-JAN-11','dd-mon-yy');
    BEGIN
      FOR days IN 1..31
      LOOP
        Dbms_Output.Put_Line(TO_CHAR(days ,'dd-Mon-yy'));
        days  := days  + 1;
      END LOOP;
    END; For employee X (ID 123), his start date is 1st and end date is 4th. So I use this query to list the dates he worked on (Jan1 jan2 jan3 jan4):
    DECLARE
    da Number;
    days Date;     
    sta emp.start%Type;
    BEGIN
    Select end-start+1
    Into da
    From emp
    where emp_id = 123;
    Select start
    Into sta
    From emp
    Where emp_id = 123;
      days  := To_Date(sta,'dd-mon-yy');
    FOR i IN 1..da
      LOOP
        Dbms_Output.Put_Line(TO_CHAR(days ,'dd-Mon-yy'));
        days  := days  + 1;
      END LOOP;
    END;Now the problem I am having is trying to do a for loop to check the work days from each employee in the table. I guess I need to iterate over the employee IDs. The above code, I entered the empoyee ID myself to find his work days, but I am trying to loop over all the employees to find and count the days. Any help on this part?
    Ultimately I am trying to get this:
    Day Count
    Jan 1 5
    Jan 2 3
    Jan 3 1
    Jan 31 5

    select  project_id,
            dt,
            nvl(count(emp_id),0)
      from  employee_projects,
            (select date '2010-12-31' + level dt from dual connect by date '2010-12-31' + level <= date '2011-01-31')
      where dt between start_date(+) and nvl(end_date(+),sysdate)
      group by project_id,
               dt
    /SY.
    Edited by: Solomon Yakobson on Jan 18, 2011 5:01 PM

  • Need to show date & a counter in my video - HELP!

    I need the date and a counter to show (superimposed?) over the video in my iMovie/iDVD. I know the date and time recorded was imported with the video files from my DV camcorder because they are available in File Info. The video recorded was a court deposition for a lawyer, and they will want the date recorded to show on the video. I'm also guessing they'll want a counter for easy access to certain parts of the video if needed. How can I do this? Is it done in iMovie or iDVD, or can it be done in both? Thanks!

    Hi Shannon:
    I answered you in the other discussion group you posted this question to:
    http://discussions.apple.com/thread.jspa?threadID=277756&tstart=0
    Please don't post in more than one forum at a time..;) Thanks!
    Sue

  • Data modelling - counter scenrio

    I need to report counters for no of sales orders on delivery block, incomplete orders and billing blocks and count backorder line items.
    I have a DSO mapped with VAITM, key fields sales doc and item no.
    I have all - delivery block, incomplete orders indicator (enhanced in data source), backorder line item indicator (if order qty is less then confirm qty) and billing blocks are mapped 1:1 in between data source and DSO.
    Key figures: no of sales orders, no of line items.
    Mapped constant = 1 in DSO.
    Now, I am thinking of creating a cube, with sales doc nos, item nos, delivery block, billing block, cal day (sys-datum) and
    key figures from DSO i.e  no of sales orders, no of line items.
    I need to be now split into new key figures : No of orders on delivery block, no of orders on billing block, no of incomplete orders, no of backorders, no of backorder line items.
    What should be the conditions in the transformation routine, so I can get correct counters with repect to system date.
    I know that I need to put some routine, which will look at change log and multiply by -1 if a delivery block is removed for an order.
    That means, I should be able to report all counters as of date (entered by users).
    Can any one explain me theoretically as well as technically.
    Please help asap.
    Thanks
    Rajiv.

    Help ?

  • OIM Managed server is frequently reaching maximum data sources count

    Hi All,
    We are using OIM 11.1.1.3.0 , Weblogic Version 10.3.3,database 11.2.0.1 for one of our client bank . Recently we encountered a problem that my oim managed server is being overloaded ,when we check the error i see data sources reaching maximum count . We have increased the maximum count to 500 and still we are facing the same issue . We also find out dead-locks in the alert log . Now,i dont understand why data sources consumption is too high .
    Please let us know your valuable inputs on the specific areas where we can check this .
    Regards,
    Nag.

    Nag,
    You don't need the developer to understand what code is causing the issue. You can analyse these issues using JRockit Mission Control, check these:
    1-http://itnaf.org/2012/06/24/jrockit-flight-recorder-into-oim-environment/
    2-http://itnaf.org/2012/08/26/jrockit-flight-recorder-analysis-into-oam-11g-environment/
    I hope this helps,
    Thiago Leoncio.

  • ODS - Number of Active Data Records count?

    Hi,
    I am having a ODS. In manage screen of ODS, i can able to see the records as shown bellow:
    Transferred records: 352053
    Added Records: 1836
    But the number of entries in Active Data of ODS is only 471 records.
    My question here is that why Added records (1836) are not equal to number of Active data records (471)? Where i am missing or is it correct?
    Best Regards,
    Venkata.

    Hi,
    Have you completed the Activation of ODS data after uploading? If no see the entries in NEW records' table of ODS.
    If you have activated already,still there is a chance to have different count, because of no of records with same value of KEY fields but exist in different packets.
    With rgds,
    Anil Kumar Sharma .P
    Message was edited by:
            Anil Kumar

  • Define date of count in CC WM

    Hello,
    We have defeined the categories as A - 4 times/year, B - 3 times/year, C - 3 times/ year and assigned to Material Master in MM, and we pass in WM for this same stock.We want to conserve the actual CC inventory procedure.
    We would like to conserve the history and not loose the last count date.
    We used to create Phy Inv doc every day, Is there any program wich permit us to charge the last Count date for our materials in WM?
    Thank you for your help.
    Best regards,
    Fatima

    Cycle count in WM is different from cycle count in IM.
    A cycle count in IM is material based, while a cycle count in WM is bin based.
    is each bin only occupied by just one material? or do you have somewhere mixed storage in a bin?
    if mixed storage, and one of the materials in the bin is due to be counted, then you have to count all materials in that bin. That is the logic in WM.
    if each bin has a single material, then you can write a report to copy the last count date from the material to the bin.

  • Table for equipement no,measurement position,date and counter reading diffe

    hi,
    i am looking for tables that could provide me following data :
    1) equipement no,
    2)measurement position(like working hours,idle hours etc.)
    3)date and
    4)counter reading difference
    I have equipment no.
    i have searched table imrg,imptt but not able to find the 2nd and 4th data
    plz help

    i gt the table IMRG and the field is CDIFF
    but its of type F.i want to read it as numeric value that cud be presented to user how cud I

Maybe you are looking for

  • Error during the migration of Lync 2013 onpremise user to Office 365 Lync

    Hi, I am trying to migrate a Lync 2013 onpremise user to Office 365 Lync in a Hybrid environment. I am connecting to the Lync server from my machine with the following commands $lyncOptions = New-PSSessionOption -SkipRevocationCheck -SkipCACheck -Ski

  • Oracle BI Discoverer 10.1.2.3

    Greetings All, In order to integrate BI Publisher with Discoverer here are the steps I found: 1.      Have access to or have Installed Oracle Application Server 10.1.2.2. Then download and install the one-off Discoverer Patch. Go to the Oracle MetaLi

  • Workitem donu00B4t see in user's inbox

    Hi all, I have any workitem that the user don´t see in your inbox workplace but when i see trought swi2_freq in the log workflow the user as responsabilite and the picture in the inbox the this user.

  • Doubt in Collection.synchronizedSet(Set s)

    hi.. I am little bit confused with the below method..can anyone pls clear me.. In java.util.Collection class public static Set synchronizedSet(Set s) //Returns a synchronized (thread-safe) set backed by the specified set. //In order to guarantee seri

  • Itunes wont update and wont download off of apple

    my itunes will not update it pops up to download then i click and nothing happens so i went to apple and was going to download it from there, i push download and run it downloads all the way but then nothing happens when it finishes