Query to pull duplicates in last 15 days

I have a table with Account and Trans_date columns. I am trying to write a query to pull the accounts that are present today and also present in the last 15 days.
[SQL]
select distinct  a.*
from
    select
            SFD.ACCOUNT,
            SFD.TRANS_DATE
    FROM CIRC_RPT.VW_SUBS_FINANCIAL_DRW SFD
    WHERE  SFD.trans_date between trunc(:Enter_date) -15 and trunc(:Enter_date)
    ) a
    join
    select
            SFD.ACCOUNT,
            SFD.TRANS_DATE
            FROM CIRC_RPT.VW_SUBS_FINANCIAL_DRW SFD
    WHERE SFD.trans_date = trunc(:Enter_date)
    )b on a.account =b.account
    order by a.account
[\SQL]
This query is pulling the duplicates but it is also pulling accounts that are only present on :Enter_date(not present in the past 15 days).
Please advice on the logic. Thanks in advance for your help.

Hi,
I think you want something like this:
SELECT  *
FROM    circ_rpt.vw_subs_financial_drw p15
WHERE   trans_date  >= TRUNC (SYSDATE) - 15
AND     trans_date  <  TRUNC (SYSDATE)
AND     EXISTS (
                   SELECT  1
                   FROM    circ_rpt.vw_subs_financial_drw
                   WHERE   account = p15.account
                   AND    trans_date = TRUNC (SYSDATE)
You can use :Enter_date instead of SYSDATE, but make sure it really is a DATE.  If :enter_date is a string, then remember to use TO_DATE.
If you do a join, you'll get duplicate rows if there happen to be 2 (or more) rows for the same account dated today.
The main problem with what you posted was that the way you checked for the past 15 days:
WHERE  SFD.trans_date between trunc(:Enter_date) -15 and trunc(:Enter_date)
Any row that met the condition for occurring on :enter_date
WHERE SFD.trans_date = trunc(:Enter_date)
would also meet the other condition, since BETWEEN includes both end-points.

Similar Messages

  • SQL query to pull duplicate employee suppliers

    We have about 11,000 employee suppliers in Oracle 11.5.10.2. At least several thousand of them are duplicates; one set of employee supplier records is in this format; JOHN R DOE
    And another set of records are in this format; Doe, Mr. John R.
    I am trying to write a query that will have two columns for each row, one employee supplier name all upper case and the other the supplier name in the second format. I then want to create a dataloader file to use for vendor merge. I realize the query won't be perfect and get all the records, but if it can get the majority I can possibly handle the remainder manually.
    I am not a coder and don't know how to write the query -- can anyone help?
    Thanks in advance.

    Wow this is bad database design!
    For starters, your query would include the original column as well as a column using the UPPER function:
    SELECT column_name, UPPER(column_name)
      FROM table_name;As for identifying duplicates, you'll have to analyze the data to see what possible formats the column values are in. I would suggest using queries using DISTINCT or GROUP BY to see what your distinct values are. You can then use REGEXP functions to parse out the values.

  • Need MDX query to find something like date diff and Date Range for last 10 days

    Hi ,
    I need two Query .First Query for below;
    I have below data in table like.
    Cat      StartDate    EndDate     
    A    2000-01-01     2000-01-15   
    B    2000-01-02     2000-01-30    
    C    2000-01-01     2000-01-31    
    D    2000-02-01     2000-02-28    
    A    2000-01-10     2000-01-31    
    I need if Startdate and Date completes whole one month then set status =1 else  0 using MDX query.
    like this ;
    Cat      StartDate    EndDate       Status
    A    2000-01-01     2000-01-15    1
    B    2000-01-02     2000-01-30    0
    C    2000-01-01     2000-01-31    1
    D    2000-02-01     2000-02-28    1
    A    2000-01-10     2000-01-31    1
    In second query I need last 10 days from current days like;
    Now = 8/20/2014
    output will be ;
    8/20/2014
    8/19/2014
    8/18/2014
    8/17/2014
    8/16/2014
    8/15/2014
    8/14/2014
    8/13/2014
    8/12/2014
    8/11/2014
    8/10/2014
    Please help me .
    Thanks

    Hi Prajapati,
    In your scenario, you can use Properties and Datediff function to achieve your requirement. Since not know the structure of your cube, we cannot give you the esact query.
     I have tested it on the AdventureWorks cube, the query below is for you reference.
    WITH MEMBER [Measures].[StartDate]
    AS
    [Employee].[Employee Department].CURRENTMEMBER.PROPERTIES('Start Date')
    MEMBER [Measures].[WorkYear]
    AS
    DATEDIFF('yyyy',[Measures].[StartDate],NOW())
    MEMBER [Measures].[Status]
    AS
    IIF(DATEDIFF('yyyy',[Measures].[StartDate],NOW())>10,1,0)
    SELECT {[Measures].[StartDate],[Measures].[WorkYear],[Measures].[Status]} ON 0,
    [Employee].[Employee Department].[Employee].MEMBERS ON 1
    FROM [Adventure Works]
    Results
    Reference
    http://msdn.microsoft.com/en-us/library/ms144821.aspx
    Regards,
    Charlie Liao
    TechNet Community Support

  • How to get count of last 30 days and total of count of rows in a single query

    Hi All,
    My requirement is to write a sql query with the following requirement
    I have a table TEST which has 6500 rows out of which the created date > 30 which means records from last 30 days are like 60.So if i write a query like this 
    Select Count(*) from TEST where CreatedDdate > 30
    This one would give me last 30 days count but in the same query i also want the count(*) which would be 6500
    So my output should be one row with 6500 in one column and 65 in second column
    Can someone please help me on how to do this?
    If you have any questions or if i am unclear please let me know.
    Thanks

    declare @sdate table(sdate date)
    insert into @sdate
    values('20150418'),('20140418')
    Select Count(*) as [total],count(case when(datediff(day,sdate,getdate()))<30 then 1 else null end) as [Last30days] from @sdate
    Hope it Helps!!

  • Query to get the new customer or updated customer in last 3 days in AR

    hi Consultants,
    we have a custom customer summary table whcih maintain the all customer details with balance and aging bucket information.
    we have program to update this custom table daily base based on the day transation. now we need to find the query to find new customer or updated customer in last 3 days.
    then we need to update the customer to custom table .
    Please advice me
    Thanks in advance
    Anu.

    Hi Vikram ,
    Thanks for your reply.
    Actually we have culoms in my custom table needs to update based on AR CUSTOMER
    below culomn needs to update in my custom table .
    CUSTOMER_ID
    ADDRESS_ID
    CUSTOMER_NUMBER
    CUSTOMER_NAME
    ADDRESS1
    ADDRESS2
    CITY
    STATE
    COUNTRY
    PHONE_NUMBER
    FAX_NUMBER
    POSTAL_CODE
    CONTACT_NAME
    COLLECTOR_CODE
    PAYMENT_TERMS
    CREDIT_LIMIT
    EXPIRATION_DATE
    DB_RATING
    DB_RISK_CLASS
    DUNNING_LETTER_STAGE
    LOCKBOX
    ACCOUNT_OPENED
    SALES_REP
    LAST_COLL_CALL_COMMENT
    FUTURE_ACTION_DATE
    ORG_ID
    LOCATION_NUMBER
    HIGH_CREDIT_LIMIT_LAST_YEAR
    HIGH_CREDIT_LIMIT_YTDPlease advice me how can we find the customer who update the above customer information in last 3 days.
    Thanks,
    Anu.

  • Query for last 8 days results

    any body have a query for last 8 days results
    TIMESTAMPADD(SQL_TSI_DAY, -8, CURRENT_DATE) this is resulting only 1 day results only .if i execute this query is it displaying 8th back day results only.
    i want all 8 back days results .
    anybody have query for this...
    Edited by: user12255470 on Apr 28, 2010 7:19 AM

    This works fine for me:
    SELECT "D0 Time"."T00 Calendar Date" saw_0, "F1 Revenue"."1-01 Revenue (Sum All)" saw_1 FROM "Sample Sales" WHERE "D0 Time"."T00 Calendar Date" BETWEEN TIMESTAMPADD(SQL_TSI_DAY, -8, CURRENT_DATE) AND TIMESTAMPADD(SQL_TSI_DAY, -1, CURRENT_DATE) ORDER BY saw_0
    regards
    John
    http://www.obiee101.blogspot.com/

  • Need to create at BEX Query to get last 30 days data.

    Hi,
    I need to create a bex query based on input date need to calculate last 30 days outstanding and 31-60 days outstanding 61-90 days outstanding 91-180 days outstanding and greater than 180 days outstanding. Please find the format of the report.Kindly help me.
                                                                                                                          Thanks & Regards,

    Based on those documents you can easily create.
    1. First create variable (Mandatory) user input
    2. Posting date is avaialble as char you will get
    3. need to calcualte difference b/w those 2 dates  you can refer below  By using replacement path we can convert both dates into get difference.
    http://www.sd-solutions.com/SAP-HCM-BW-Replacement-Path-Variables.html
    4. now need to create  Bucketing logic  formula  as per requirement above documents will give idea.

  • Query for getting Last 4 Day of weeks - need help

    I am having a table profile that contains a column 'Modified_Date' that stores date values. The table contains records for the last one month.
    Now, I need a query that gives me the last 3 wednesdays (Including today)
    i.r,. I need the last 4 wednesdays including today.
    How can I acheive this.
    Thanks in advance.
    Regards
    Raghu.

    Hi,
    explain? I'll try.
    Level is a pseudocolumn used in conjunction with connect by. In connect by I used < 5 as a condition since you wanted the last 4 Wednesday. I used it to get a number to be used as a multiplier.
      1  select next_day(sysdate,'wednesday')-(7*level) weds, level lvl from dual
      2* connect by level < 5
    SQL> /
    WEDS             LVL
    06-AUG-08          1
    30-JUL-08          2
    23-JUL-08          3
    16-JUL-08          4
    next_day(p_date,'wednesday') returns the calendar date of Wednesday after the date in p_date
    (7*level) a week is composed of seven (7) days multiplied by level or number of weeks to get number of days between weeks. I then subtract this from the result of next_day function

  • Select Last  X days when execute query

    Hello,
    ı need  last N stop date of machines in my query, ı have stop date and when ı execute the query ı want to see just last 3 stop. have can ı make it?
    the filters of my query  are: Fiscal Year and Fiscal Period.
    ı cant give any condition because stop date is not key figure,has anyone any ideas??

    you can create condition on the stop date irrespective of key figure or not.
    Create the formual which has condition
    ( A  = B) * C + D
    The above statment means:
    If A = B
    then Display C
    or Display D.

  • Last Working Day Variable

    Hello Folks,
    Any idea about the Std Variable for the last working day calculation.
    I have a customised Characteristics to which I want to use this variable then what steps should I follow or by installing it through  content will it directly get attached, I mean will be available while choosing the variables for this characteristics in a query.
    Thanks,
    Suyog.

    Hi,
    Create a customer exit variable to get last working day of the month and write the following logic in ZXRSRU01:
    *Last working day of the given period(Cal Yr/Month)
    WHEN '<Customer exit variable>'.
    DATA : BEGIN OF i_holidays OCCURS 0.
            INCLUDE STRUCTURE iscal_day.
    DATA : END OF i_holidays,
          v_fdate LIKE sy-datum,
          v_ldate LIKE sy-datum.
        IF i_step = 2.
          READ TABLE i_t_var_range INTO loc_var_range
                WITH KEY vnam = '<Cal yr/month selection variabel>'.
          IF sy-subrc = 0.
              CONCATENATE loc_var_range-low
                          '01' INTO v_fdate.
    * to get last day of the given period
              CALL FUNCTION 'SLS_MISC_GET_LAST_DAY_OF_MONTH'
                EXPORTING
                  day_in            = v_fdate
                IMPORTING
                  last_day_of_month = v_ldate.
    *To get holiday list in the given period
                CALL FUNCTION 'HOLIDAY_GET'
                  EXPORTING
                    holiday_calendar = <Fact cal ID>
                    factory_calendar = <Fact cal ID>
                    date_from        = v_fdate
                    date_to          = v_ldate
                  TABLES
                    holidays         = i_holidays.
              SORT i_holidays BY date DESCENDING.
              DELETE ADJACENT DUPLICATES FROM i_holidays.
              DO.
                READ TABLE i_holidays WITH KEY date = v_ldate.
                IF sy-subrc NE 0.
                  v_ldate = v_ldate - 1.
                ELSE.
                  l_s_range-sign = 'I'.
                  l_s_range-opt = 'EQ'.
                  l_s_range-low = v_ldate.
                  APPEND l_s_range TO e_t_range.
                  CLEAR:l_s_range.
                    EXIT.
                  ENDIF.
              ENDDO.
         ENDIF.
        ENDIF.
    Assumptions:
      Running a report by entering Cal yr/month as selection value.
    hope it works...
    regards,
    Raju

  • I am having problems using Firefox with Ebay in the last 10 days. The advanced search link is dropping off the page and there is no way to access it now.

    I have been using Firefox and Ebay for at least 12 years with no problems whatsoever. But in the last 10 days I have been having trouble with the Advanced Search link disappearing from the page on Ebay. If I do a search from the Ebay home page it will show the results, but the Advanced Search link (in blue letters) which always used to appear to the right of the Search button is gone. If I click Search again at this point I can see the Advanced Search link appear for a millisecond, but then disappear just as quickly. Also, if I refresh the page the same thing happens. I tried to duplicate this problem with Internment Explorer and it didn't occur, so it appears to be Firefox that is causing this issue. Of course when I contacted Ebay they told me my problem was that I wasn't using Internment Explorer! I love Firefox and do not want to switch!

    You can try to clear the cache and cookies to see if that makes a difference:
    <h3>Clearing Cache</h3>
    #Go to Firefox > History > Clear recent history or (if no Firefox button is shown) go to Tools > Clear recent history.
    #Under "Time range to clear", select "Everything".
    #Now, click the arrow next to Details to toggle the Details list active.
    #From the details list, check ''Cache'' and uncheck everything else.
    #Now click the ''Clear now'' button.
    <h3>Clearing Cookies</h3>
    #Go to Firefox > Tools > Privacy > Remove Individual Cookies
    #Find the site (ebay.com) that's having problems and clear all cookies.
    #Restart Firefox
    Further information can be found in the [[Clear your cache, history and other personal information in Firefox]] article.

  • Latest Address and the Previous Address in the last 30 days

    Morning folks.
    I need to find out all Customers whose Address changed based on the Effective Date. The Query should be based as of Effective Date 01-JUN-12 and not SYSDATE. So, we want to check the MAX(effective_date) is <= 01-JUN-12 and the Previous Address's Effective Date is between 02-MAY-12 and 01-JUN-12 (30 days). This would suggest that an Address has changed. For argument sake, the Zip Code is enough to differentiate that an address has changed for now.
    Based on the data, I only want to pick up Customer 1002 but not 1001, 1003. As for Customer ID 1003, even though his/her address changed in the last 30 days, we are not interested as the Address effective 1st June was good for a long time.
    Also, even though the Address for Customer ID 1001 changed twice in that period, I am only interested for the latest two addresses.
    Table CUST_ADDRESS
    CREATE TABLE CUST_ADDRESS
        "CUST_NO"  VARCHAR2(4 BYTE) NOT NULL,
        "STREET"   VARCHAR2(20 BYTE),
        "CITY"     VARCHAR2(20 BYTE),
        "STATE"    VARCHAR2(2 BYTE),
        "ZIP_CODE" VARCHAR2(9 BYTE),
        "EFFECTIVE_DATE" DATE
      );INSERT Script
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1001','123 Picket Fences','Santa Ana','CA','92704',to_date('31-MAY-12','DD-MON-RR'));
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1001','12259 Circular Dr','Irvine','CA','92705',to_date('10-APR-12','DD-MON-RR'));
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1001','22 Green Road','Newport Beach','CA','92709',to_date('03-JAN-12','DD-MON-RR'));
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1002','12 Parkside Dr','Chicago','IL','60601',to_date('20-MAY-12','DD-MON-RR'));
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1002','3200 Court Road','Indianapolis','IN','46201',to_date('02-MAY-12','DD-MON-RR'));
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1003','24 Jaeger St','Bellingham','WA','98225',to_date('01-JUL-12','DD-MON-RR'));
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1003','145 NE 38th St','Fort Lauderdale','FL','33334',to_date('18-JUN-12','DD-MON-RR'));
    Insert into CUST_ADDRESS (CUST_NO,STREET,CITY,STATE,ZIP_CODE,EFFECTIVE_DATE) values ('1003','212 Coral Drive','Miami','FL','33010',to_date('01-JAN-95','DD-MON-RR'));Thanks a bunch.
    Edited by: Roxyrollers on Jul 26, 2012 9:35 AM

    Something like this
    SQL> ed
    Wrote file afiedt.buf
      1  select *
      2    from (
      3  select ca.*,
      4         max(effective_date) over (partition by cust_no) max_eff_date,
      5         lag(effective_date) over (partition by cust_no order by effective_date) prior_eff_date
      6    from cust_address ca)
      7   where prior_eff_date between date '2012-05-02' and date '2012-06-01'
      8*    and max_eff_date <= date '2012-06-01'
    SQL> /
    CUST STREET               CITY                 ST ZIP_CODE  EFFECTIVE MAX_EFF_D PRIOR_EFF
    1002 12 Parkside Dr       Chicago              IL 60601     20-MAY-12 20-MAY-12 02-MAY-12Justin

  • How to get the last seven days for out put of present day

    Hi Experts,
    we developed one query for 3 years data
    1.user enter the current date (21-03-2014) but out put value should be last seven days (21-03-2014 - 7) (last one week data only)
    2.some times user will enter the (20-03-2014 ) but out put value should be last seven days (20-03-2014 - 7) (last one week data only)
    how to achieve the 2 different scenario?
    is there any standard variable ? please suggest .
    Thanks,
    Bindu.

    Hi,
    i created the Characteristic value variable not formula variable
    in char variable i can't see the off set functionality but we can see off set function in formula variable
    user requirement he wants enter the input value as date and he need last week data means one week data calday wise.
    i tired the 0PREVWK , 0CWEEK these two variables these not asking the input and direct showing the out put.
    these can achieve through the customer exit?
    Thanks,
    Bindu.

  • In the last few days iTunes on my iMac 21.5" has been launching unexpectedly and repeatedly. I have OSX 10.7.2 and iTunes 10.5.3 installed. Any ideas?

    In the last few days iTunes on my iMac intel 21.5" has been launching unexpectedly and repeatedly. I have OSX 10.7.2 and iTunes 10.5.3 installed and usually only Mail and Safari running, although it makes no difference what else is actually running. Any ideas?

    Thanks for the reply. I don't use MobileMe, so it shouldn't have been that. I did a complete computer reset by shutting down, pulling the plug for several minutes. Since then, the problem has not reappeared, so I'm hoping that the problem has been solved.

  • Custom report for TOP 10 CPU Utilization machines from any group in aggregation last seven days

    I want to create a custom report that contain list of TOP CPU Utilization of machines form any group.This report is create on last 7 days CPU utilization of all machine from a group.
    What  should be query for this report.

    Hi,
    Please refer to the links below:
    SQL Query for TOP 10 Average CPU
    https://social.technet.microsoft.com/Forums/systemcenter/en-US/8d9a2d0d-8761-4d1f-b194-b24aa65172e1/sql-query-for-top-10-average-cpu?forum=operationsmanagerreporting
    How to use Report Builder to create custom reports in SCOM 2007
    http://www.systemcentercentral.com/how-to-use-report-builder-to-create-custom-reports-in-scom-2007/
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact [email protected]

Maybe you are looking for

  • "computer not authorized to play"

    Just bought the G3S and it has messed up my itunes syncing. It would not sync most of my apps. They are on my computer but don't transfer to my iphone. Some video and music does not transfer saying that the computer is not authorized to play the item

  • Download Itunes 10 64bit with Windows 7 "Freezes"

    I have attempted downloading Itunes 10 64bit on my new ASUS PC with Windows 7. It starts to download then "Freezes" at about 20-25mbs. I am using agood broadband connection. Is the software available on anyother media ie: CD rom?

  • Fonts in Report

    I need different fonts in one ITEM on a report. Can I put scape characters in a table column? Thanks.

  • Question about AppleScript, iTunes and the app Proximity...

    So I have this application Proximity, which uses bluetooth's proximity to the cpu to run both an out-of-range script and and in-range script. I'm currently using it to activate my screensaver with password lock and vice versa. I'm also using it to sy

  • Adding special prices to items query.

    Hi, I'm just wondering if anybody can help me work out how to add special prices to items on a volume basis. say if i sold one item there would be no discount but if i sold 10 then i would automatically want a 5% discount to be given, I've had a look