Status of part query help

Hi, I have a part, and it can be received, accepted, rejected, corrected and shipped. This is held in the status field. It is on the line level, so each part also has a line number associated with the transactions status, i.e.
Part PO Line Status
12345 1 Received
12345 2 Rejected
I need to know how many parts for each po line only have a status of rejected. They must never have been received, rejected, corrected or shipped, only received.
I don't know where to begin, thank you for any help.

Hi,
The query I posted doesn't consider the order of events at all. As posted, it finds 'Rejected' rows without a matching 'Corrected' or 'Shipped' row, regardless of which came first.
If order is important, you might be able to modify the query I posted.
For example, the query below finds 'Rejected' rows that were not followed by "Corrected' or 'Shipped': any status *before* the 'Rejected' (sorting by po_line) is okay:
{code}
SELECT     *
FROM     part_table     m     -- m for main
WHERE     status     = 'Rejected'
AND     NOT EXISTS (     SELECT     1
               FROM     part_table
               WHERE     part     = m.part
               AND     status     IN ('Corrected', 'Shipped')
               AND     po_line     > m.po_line          -- <== NEW
{code}
Depending on what you need to do, there might be better ways.
Boneist had a good idea: post some sample data, showing different situations that you need to handle, and the results you want from that data.

Similar Messages

  • SQL Query Help - Is this possible or impossible????

    Hi guys,
    I need help with an SQL query that I'm trying to develop. It's very easy to explain but when trying to implement it, I'm struggling to achieve the results that I want.....
    For example,
    I have 2 tables
    The first table is:
    1) COMPANY create table company (manufacturer varchar2(25),
                                                          date_established date,
                                                          location varchar2(25) );My sample test date is:
    insert into company values ('Ford', 1902, 'USA');
    insert into company values ('BMW', 1910, 'Germany');
    insert into company values ('Tata', 1922, 'India');The second table is:
    2) MODELS create table models (manufacturer varchar(25),
                                                 model varchar2(25),
                                                 price number(10),
                                                 year date,
                                                 current_production_status varchar2(1) ) ;My sample test data is:
    insert into models values ('Ford', 'Mondeo', 10000, 2010, 0);
    insert into models values ('Ford', 'Galaxy', 12000,   2008, 0);
    insert into models values ('Ford', 'Escort', 10000, 1992, 1);
    insert into models values ('BMW', '318', 17500, 2010, 0);
    insert into models values ('BMW', '535d', 32000,   2006, 0);
    insert into models values ('BMW', 'Z4', 10000, 1992, 0);
    insert into models values ('Tata', 'Safari', 4000, 1999, 0);
    insert into models values ('Tata', 'Sumo', 5500,   1996, 1);
    insert into models values ('Tata', 'Maruti', 3500, 1998, 0);And this is my query:
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer IN ('Ford', 'BMW', 'Tata')
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCWhat I want the query to output is this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               Sumo               5500               1998          1If current_production_status is 1 it means this particular model has been discontinued
    If current_production_status is 0 it means the manufacturer does not have any discontinued models and all are in procuction.
    The rule is only one record per manufacturer is allowed to have a current_production_status of 1 (so only one model from the selection the manufactuer offers is allowed to be discontinued).
    So the query should output the one row where current_production_status is 1 for each manufacturer.
    If for a given manufacturer there are no discontinued models and all have a current_production_status of 0 then ouput a SINGLE row that only includes the data from the COMPANY table (as above). The rest of the columns from the MODELS table should be populated with a '-' (hyphen).
    My query as it is above will output all the records where current status is 1 or 0 like this
    com.manufacturer        com.date_established          com.location          mod.model          mod.price          mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    Tata               1922                    India               Sumo               5500               1998          1
    Ford               1902                    USA               -               -               -          0                    
    Ford               1902                    USA               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    BMW               1910                    Germany               -               -               -          0
    Tata               1922                    India               -               -               -          0
    Tata               1922                    India               -               -               -          0However this is not what I want.
    Any ideas how I can achieve the result I need?
    Thanks!
    P.S. Database version is '10.2.0.1.0'

    Hi Vishnu,
    Karthiks query helped...
    But this is the problem I am facing...
    SELECT
            com.manufacturer,
            com.date_established,
            com.location,
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.model),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.price),
            DECODE(nvl(mod.current_production_status, '0'), '0', '-', mod.year),
            mod.current_production_status
    FROM
           company com,
           models mod
    WHERE
          mod.manufacturer = com.manufacturer
          and com.manufacturer = 'Ford'
          and mod.current_production_status IN (1,0)
    ORDER BY
            mod.current_production_status DESCThe value of:
    and com.manufacturer = 'Ford'will be dependent on front end user input....
    When I run the query above I get all the rows where current_production_status is either 1 or 0.
    I only require the rows where current_production_status is 1.
    So if I amend it to look like this:
         and mod.current_production_status = 1This works....
    BUT if a user now passes in more than one manufacturer EG:
    and com.manufacturer IN ('Ford', 'BMW')The query will only return the one row for Ford where current_production_status is 1. However because BMW has no models where current_production_status is 1 (all 3 are 0), I still want this to be output - as one row....
    So like this:
    com.manufacturer        com.date_established          com.location          mod.model          mod.price             mod.year     mod.current_production_status
    Ford               1902                    USA               Escort               10000               1992          1
    BMW               1910                    Germany               -               -               -          0So (hopefully you understand), I want both cases to be catered for.....whether a user enters one manufacturer or more than one...
    Thanks you so much!
    This is really driving me insane :-(

  • Query Help-2

    Query Help:
    http://forum.java.sun.com/thread.jsp?forum=45&thread=471180&tstart=15&trange=15
    It seems I have confused enough people with my improper presentation of query. Sorry guys. I will restate my question with different table names.
    The above was my previous posting, which was not clear..so Iam restating my problem as follows....
    I have the following tables
    Customer(custID, Name, Address)
    Order(custID, OrderID, orderDate)
    CreditCard(custID, creditCard#, creditCardType)
    Now if I have 3 records in Order with custID 100 and 2 records in CreditCard as
    Order:
    100,A001,11/22/03
    100,A002,11/24/03
    100,A003,12/02/03
    CreditCard:
    100,42323232..., VISA
    100,5234234...., MASTER
    Now how can I get
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    data in minimum no. of records....
    I think I have made my query clear..
    now please help me guys...
    thanks so much for your help.

    You are right.
    But frankly the actual tables on my database are not customer,orders and creditcards..but I just tried to reproduce the problem with these tables, please ignore that user needs a refund etc situtaion. If the tables were actually order,creditcards etc..it would have been a problem to be considered.
    Can you please help me with the query
    if I have m rows in Order and n rows in CreditCard. I will get m*n records, I looking for max(m,n).
    With the following fields in my query result,
    custID, Name, Address, OrderID, orderDate, creditCard#, creditCarType
    from Customer, Order, CreditCard tables
    Thanks so much for your htlp

  • HT4211 I'm not able to download apps from App Store. It never downloads and it shows waiting status.can somebody please help me resolve this issue

    I'm not able to download apps from App Store. It never downloads and it shows waiting status.can somebody please help me resolve this issue

    I really do not think it is the iPad or your network connection. Other users have reported this very same issue. Try this and see if it works for you - it may not work - but it's easy to try - harmless - and it has worked in the past for others.
    Try signing out of your account and restart your iPad.
    Go to Settings>Store>Apple ID and tap the ID and sign out. Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button. Go back to Settings>Store> Apple ID and sign in again.

  • Workflow status web part gives error when going back to previous stage (using GO TO) in Project Server 2013 workflow

    Hi,
    Workflow status web part gives error when going back to previous stage (using GO TO) transition activity  in Project Server 2013 workflow.
    Please guide how to create a workflow which restarts from a desired stage.

    Thanks for your prompt reply....
    It gives following error
    Workflow Status
    This Web Part was unable to load.
    Information that may be useful in solving this problem was written to the Unified Logging Service (ULS) log on the Project Web App with the following ID: e95a9c9c-1f68-90d7-0a3e-5951df70fec6
    For more information, contact your Project Web App administrator.
    what do you mean to restart the Project Server 2013 with different project name, please elaborate....

  • Need a query help

    hii
    i need a query help
    i have two tables
    the 1st table will look like this
    associate id weekid no.of. hours
    4000 810 40
    4000 820 30
    4000 830 60
    4000 840 70
    2nd table will look like this
    associate id weekid no.of.hours
    4000 810 40
    4000 820 70
    4000 830 130
    4000 840 200
    so when i subtract the last two records frm each other in the second table the value should be equal to the no.of.hours in the first table.. for example
    the query shud consider the last record and one before the last record and the difference between two records shud be equal to the value in the 1st table
    for example
    consider week id 830 and 840
    in second table 830=130
    840=200
    when u subtraced both values the difference shud be equal to value in the 1st table for tht week id
    1 ---->>>> 840 - 830
    =200 - 130
    =70
    in first table 840 has 70 hrs
    like this it shud check with all records and it shud return only the records which are not equal
    regards
    srikanth

    This..?
    sql>select * from t1;
    A_ID W_ID HRS
    4000  810  40 
    4000  820  30 
    4000  830  60 
    4000  840  70 
    4000  850  80 
    sql>select * from t2;
    A_ID W_ID HRS 
    4000  810  40 
    4000  820  70 
    4000  830  130 
    4000  840  200 
    4000  850  260 
    sql>
    select a_id,w_id,hrs,sum_hrs
    from(
    select t1.a_id a_id,t1.w_id w_id,t1.hrs hrs,t2.hrs sum_hrs,
           t2.hrs - nvl(lag(t2.hrs)  over(order by t1.w_id),0) diff
    from t1,t2
    where t1.w_id = t2.w_id)
    where diff != hrs;
    A_ID W_ID HRS SUM_HRS 
    4000  850  80  260                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to delete credit card info under my Apple ID?  there is no "None" button under payment info part.  Help! many thanks

    how to delete credit card info under my Apple ID?  there is no "None" button under payment info part.  Help! many thanks

    All you can do is contact iTunes:
    Apple - Support - iTunes - Contact Us

  • I bought Apple TV3 , it was working fine until today and stopped showing the status light. Please help.

    I bought Apple TV3 , it was working fine until today and stopped showing the status light. Please help.

    try another cable it's a std cable that most consumer electronic use
    if that does not help then I would try to connect it by a microUSB cable to see if I could restore the firmware from a computer running itunes
    if that does not help then I would say that the appletv have died

  • Query help, subtract two query parts

    Hi,
    I am beginner of PL/SQL and have a problem I couldn’t solve:
    Table (op_list):
    Item     -     Amount -     Status
    Item1     -     10     -     in
    Item2     -     12     -     in
    Item3     -     7     -     in
    Item1     -     2     -     out
    Item2     -     3     -     out
    Item1     -     1     -     dmg
    Item3     -     3     -     out
    Item1     -     2     -     out
    Item2     -     5     -     out
    Item2     -     2     -     in
    Item3     -     1     -     exp
    Would like to get result of query (subtract amount of 'out/dmg/exp' from 'in' ):
    Item - Amount left
    Item1     -     5
    Item2     -     6
    Item3 -     3
    I wrote code that returns sum of all incoming items and sum all out/dmg/exp items, but couldn’t solve how to subtract one part of querry from another. Or maybe there is a better way. Also worried what happens if there is no 'out/dmg/exp' only 'in'
    select item.name, sum(op_list.item_amount)
    from op_list
    inner join item
    on op_list.item = item.item_id
    where op_list.status = 'in'
    group by item.name
    union
    select item.name, sum(op_list.item_amount)
    from op_list
    inner join item
    on op_list.item = item.item_id
    where op_list.status = 'out'
    or op_list.status = 'dmg'
    or op_list.status = 'exp'
    group by item.name
    Return:
    Item1     -     10      [10 in]
    Item1     -     5     [2+1+2]
    Item2     -     14     [12+2]
    Item3     -     7
    Item3     -     4     [3+1]
    Thanks in advance

    Hi,
    We can also use simple inline views to get what we need.
    select a.item,a.amount-b.amount Balance from
    (select item,sum(amount) Amount from op_list
    where status = 'in'
    group by item) a,
    (select item,sum(amount) Amount from op_list
    where status in ('out','dmg','exp')
    group by item) b
    where
    a.item=b.item
    order by item;
    ITEM       BALANCE
    Item1                      5
    Item2                      6
    Item3                      3Regards,
    Prazy

  • Need help in displaying the status in one query

    Query:
    SELECT START_DATE,END_DATE,ABSENCE_TYPE,APPROVAL_STATUS,SUM(ABSENCE_DAYS),absence_attendance_id FROM(
    SELECT *
    FROM (SELECT NVL (paa.date_start, paa.date_projected_start) start_date,
    NVL (paa.date_end, paa.date_projected_end) end_date,
    paattl.NAME absence_type,
    (SELECT meaning
    FROM hr_lookups
    WHERE 'A' = lookup_code(+)
    AND 'LEAVE_STATUS' = lookup_type(+)) approval_status,
    NVL(paa.absence_days,
    hr_absutil_ss.getabsdurdays
    (paat.absence_attendance_type_id,
    paa.business_group_id,
    paa.creation_date,
    paa.person_id,
    paa.date_projected_start,
    paa.date_projected_end,
    paa.time_projected_start,
    paa.time_projected_end
    ) absence_days,
    paa.absence_attendance_id
    FROM per_absence_attendances paa,
    per_absence_attendance_types paat,
    per_abs_attendance_types_tl paattl,
    hr_lookups fcl
    WHERE paa.person_id = 155253
    AND paa.business_group_id = 112
    AND paa.absence_attendance_type_id =
    paat.absence_attendance_type_id
    AND paat.absence_attendance_type_id =
    paattl.absence_attendance_type_id
    AND paattl.LANGUAGE = USERENV ('LANG')
    AND fcl.lookup_type(+) = 'ABSENCE_CATEGORY'
    AND paat.absence_category = fcl.lookup_code(+)
    AND ( ( hr_api.return_legislation_code
    (paat.business_group_id) =
    'GB'
    AND NVL (paat.absence_category, '#') NOT IN
    ('M', 'GB_PAT_ADO', 'GB_PAT_BIRTH', 'GB_ADO')
    OR ( hr_api.return_legislation_code
    (paat.business_group_id) <>
    'GB'
    AND NVL (paat.absence_category, '#') NOT IN
    ('GB_PAT_ADO', 'GB_PAT_BIRTH', 'GB_ADO')
    AND NOT EXISTS (
    SELECT 'e'
    FROM hr_api_transactions t
    WHERE t.selected_person_id = paa.person_id
    AND t.creator_person_id = NVL (155253, t.creator_person_id)
    AND t.transaction_ref_table = 'PER_ABSENCE_ATTENDANCES'
    AND t.transaction_ref_id = paa.absence_attendance_id
    AND NOT ( hr_absutil_ss.getabsencetype
    (t.transaction_id,
    NULL
    ) IS NULL
    AND t.status = 'W'
    AND t.status NOT IN ('D', 'E'))
    UNION ALL
    SELECT hr_absutil_ss.getstartdate (hat.transaction_id,
    NULL
    ) start_date,
    hr_absutil_ss.getenddate (hat.transaction_id, NULL) end_date,
    hr_absutil_ss.getabsencetype
    (hat.transaction_id,
    NULL
    ) absence_type,
    hr_absutil_ss.getapprovalstatus
    (hat.transaction_id,
    NULL
    ) approval_status,
    hr_absutil_ss.getabsencedaysduration
    (hat.transaction_id,
    NULL
    ) absence_days,
    hat.transaction_ref_id absence_attendance_id
    FROM hr_api_transactions hat, hr_api_transaction_steps hats
    WHERE hat.transaction_ref_table = 'PER_ABSENCE_ATTENDANCES'
    AND hat.transaction_group = 'ABSENCE_MGMT'
    AND hat.transaction_identifier = 'ABSENCES'
    AND hat.transaction_ref_id IS NOT NULL
    AND hat.selected_person_id = 155253
    AND hat.creator_person_id = NVL (155253, hat.creator_person_id)
    AND hat.transaction_id = hats.transaction_id(+)
    AND hat.status NOT IN ('D', 'E')
    AND NOT ( hr_absutil_ss.getabsencetype (hat.transaction_id,
    NULL
    ) IS NULL
    AND hat.status = 'W'
    -- WHERE start_date = to_date(c_start_time) and end_date = to_date(c_stop_time)
    where absence_type NOT IN ('Emergency Call Up Military','On/Off Ramp','Paternity Leave','Maternity Leave'
    ,'Medical Leave','Parental Leave','Personal Leave','Bereavement Leave'
    ,'Marriage Leave','Moving House Leave','Military Duty Leave','Paternity','Adoption Leave',
    'Bereavement') ORDER BY start_date DESC )
    WHERE approval_status IN ('Pending For Approval','Approved','Rejected')
    GROUP BY START_DATE,END_DATE,ABSENCE_TYPE,APPROVAL_STATUS,absence_attendance_id;
    Current Output:
    Start_date End_date absence_type approval_status sum(absence_days) absence_attendance_id
    8/12/2010 8/13/2010 Standard Vacation Approved 2 10006531
    6/10/2011 6/10/2011 Standard Vacation Pending For Approval 1 10833750
    Expected Output:
    Start_date End_date absence_type approval_status sum(absence_days) absence_attendance_id
    8/12/2010 8/13/2010 Standard Vacation Approved 2 10006531
    6/10/2011 6/10/2011 Standard Vacation Submitted 1 10833750
    I need to change the "Pending for Approval " status to "Submitted".I tried using DECODE but not working.Can anyone help?
    Other Status will not be changing.
    Thanks
    Hibin

    /* Formatted on 6/24/2011 7:30:30 AM (QP5 v5.149.1003.31008) */
      SELECT START_DATE,
             END_DATE,
             ABSENCE_TYPE,
             DECODE (APPROVAL_STATUS,
                      'Submitted',
                      'Pending for Approval',
                      APPROVAL_STATUS)
                APPROVAL_STATUS,
             SUM (ABSENCE_DAYS),
             absence_attendance_id
        FROM (  SELECT *
                  FROM (SELECT NVL (paa.date_start, paa.date_projected_start)
                                  start_date,
                               NVL (paa.date_end, paa.date_projected_end) end_date,
                               paattl.NAME absence_type,
                               (SELECT meaning
                                  FROM hr_lookups
                                 WHERE 'A' = lookup_code(+)
                                       AND 'LEAVE_STATUS' = lookup_type(+))
                                  approval_status,
                               NVL (paa.absence_days,
                                    hr_absutil_ss.
                                     getabsdurdays (paat.absence_attendance_type_id,
                                                    paa.business_group_id,
                                                    paa.creation_date,
                                                    paa.person_id,
                                                    paa.date_projected_start,
                                                    paa.date_projected_end,
                                                    paa.time_projected_start,
                                                    paa.time_projected_end))
                                  absence_days,
                               paa.absence_attendance_id
                          FROM per_absence_attendances paa,
                               per_absence_attendance_types paat,
                               per_abs_attendance_types_tl paattl,
                               hr_lookups fcl
                         WHERE paa.person_id = 155253 AND paa.business_group_id = 112
                               AND paa.absence_attendance_type_id =
                                      paat.absence_attendance_type_id
                               AND paat.absence_attendance_type_id =
                                      paattl.absence_attendance_type_id
                               AND paattl.LANGUAGE = USERENV ('LANG')
                               AND fcl.lookup_type(+) = 'ABSENCE_CATEGORY'
                               AND paat.absence_category = fcl.lookup_code(+)
                               AND ( (hr_api.
                                       return_legislation_code (
                                         paat.business_group_id) = 'GB'
                                      AND NVL (paat.absence_category, '#') NOT IN
                                             ('M',
                                              'GB_PAT_ADO',
                                              'GB_PAT_BIRTH',
                                              'GB_ADO'))
                                    OR (hr_api.
                                         return_legislation_code (
                                           paat.business_group_id) <> 'GB'
                                        AND NVL (paat.absence_category, '#') NOT IN
                                               ('GB_PAT_ADO',
                                                'GB_PAT_BIRTH',
                                                'GB_ADO')))
                               AND NOT EXISTS
                                          (SELECT 'e'
                                             FROM hr_api_transactions t
                                            WHERE t.selected_person_id =
                                                     paa.person_id
                                                  AND t.creator_person_id =
                                                         NVL (155253,
                                                              t.creator_person_id)
                                                  AND t.transaction_ref_table =
                                                         'PER_ABSENCE_ATTENDANCES'
                                                  AND t.transaction_ref_id =
                                                         paa.absence_attendance_id
                                                  AND NOT (hr_absutil_ss.
                                                            getabsencetype (
                                                              t.transaction_id,
                                                              NULL)
                                                              IS NULL
                                                           AND t.status = 'W')
                                                  AND t.status NOT IN ('D', 'E'))
                        UNION/**/ ALL
                        SELECT hr_absutil_ss.getstartdate (hat.transaction_id, NULL)
                                  start_date,
                               hr_absutil_ss.getenddate (hat.transaction_id, NULL)
                                  end_date,
                               hr_absutil_ss.
                                getabsencetype (hat.transaction_id, NULL)
                                  absence_type,
                               hr_absutil_ss.
                                getapprovalstatus (hat.transaction_id, NULL)
                                  approval_status,
                               hr_absutil_ss.
                                getabsencedaysduration (hat.transaction_id, NULL)
                                  absence_days,
                               hat.transaction_ref_id absence_attendance_id
                          FROM hr_api_transactions hat, hr_api_transaction_steps hats
                         WHERE hat.transaction_ref_table = 'PER_ABSENCE_ATTENDANCES'
                               AND hat.transaction_group = 'ABSENCE_MGMT'
                               AND hat.transaction_identifier = 'ABSENCES'
                               AND hat.transaction_ref_id IS NOT NULL
                               AND hat.selected_person_id = 155253
                               AND hat.creator_person_id =
                                      NVL (155253, hat.creator_person_id)
                               AND hat.transaction_id = hats.transaction_id(+)
                               AND hat.status NOT IN ('D', 'E')
                               AND NOT (hr_absutil_ss.
                                         getabsencetype (hat.transaction_id, NULL)
                                           IS NULL
                                        AND hat.status = 'W'))
                 -- WHERE start_date = to_date(c_start_time) and end_date = to_date(c_stop_time)
                 WHERE absence_type NOT IN
                          ('Emergency Call Up Military',
                           'On/Off Ramp',
                           'Paternity Leave',
                           'Maternity Leave',
                           'Medical Leave',
                           'Parental Leave',
                           'Personal Leave',
                           'Bereavement Leave',
                           'Marriage Leave',
                           'Moving House Leave',
                           'Military Duty Leave',
                           'Paternity',
                           'Adoption Leave',
                           'Bereavement')
              ORDER BY start_date DESC)
       WHERE approval_status IN ('Pending For Approval', 'Approved', 'Rejected')
    GROUP BY START_DATE,
             END_DATE,
             ABSENCE_TYPE,
             APPROVAL_STATUS,
             absence_attendance_id;

  • QUERY HELP!!! trying to create a query

    i'm creating a summary report
    i have a table with sale dates
    for example i have a table tab_1 and column saleDate as
    saleDat
    1923
    1936
    1945
    2003
    2005
    saleDate contains years and there are some missing years where no sale
    was made
    My report has to display years starting from earliest year
    so i have to create a query that starts with 1923
    but the problem is that I have to have years that are not in table.
    for example i have to display years 1924 which is not in table
    so the part of report has to look like
    1923 blah blah summary.........
    1924 "
    1925
    1926
    2005
    2006
    upto current year (2006 may not be in the table, but i have to display)
    i just need to know the query that can query all the years starting from
    the ealiest saleDate to current year
    thanks in advance

    Please write the query in the following form:
    SELECT a.year, --- place other columns from your table.
    FROM (SELECT (:start_num + rownum) year
    FROM all_tab_columns
    WHERE :start_num + rownum <= :end_num) a,
    tab_1 b
    WHERE a.year = b.saleDat(+);
    Note:
    1) if your start year and end year are 1923 and 2006. Then input as below:
    :start_num = 1922
    :end_num = 2006
    2) Since for some of the years (1924 etc) may not be there in your so you may need to use NVL to print proper indicators.
    3) If you have more than one record in tab_1 for a particular year then group them based year and then use it.
    Hope this helps.
    - Saumen.

  • Query Help Please

    Hi... having problems with a query.  Any assistance would be
    much appreciated.
    Two queries with identical columns: Villages_Query_1 and Villages_Query_2.
    Both have these columns: Village_ID, Village_Name, Player_ID.
    I need to find all records in Villages_Query_2 where the Village_ID's match but the Player_ID's have changed.
    Example Village_Query_1
    Village_ID
    Village_Name
    Player_ID
    1
    Houston
    1
    2
    Dallas
    2
    3
    Chicago
    3
    Example Village_Query_2
    Village_ID
    Village_Name
    Player_ID
    1
    Houston
    1
    2
    Phoenix
    4
    3
    Chicago
    3
    4
    New York
    5
    In this case, Village_ID = 2, has changed names (Dallas to Phoenix) and the Player_ID has changed (2 to 4).  In addition, a new record was added.
    The eventual output I need is to be able to report the following:
    Player 2 village "Dallas" was taken by Player 4 and renamed "Phoenix".
    New York is a new village owned by Player 5.
    How the heck do I do this??  I have been trying query after query... reading about query of queries and JOINS and and and... I am now completely confused.
    Help appreciated.
    Mark

    Well... firstly... you do not use MS Access for that volume of data.  Plain and simple.  MS Access is for DBs like "My CD collection".  It's a desktop application, and is not intended to be used other than as a desktop application.
    Part of the reason for it not being appropriate for the job is that it can't do things like bulk loading data, which is kinda what you're wanting to do here.  That aside, it's a single-user file-based DB which is simply not designed to work as the back-end for a web application (or any sort of serious application).
    Anyway, I would approach this by putting all the data from the CSV files into the DB as is.  Then on the DB run a query which gets all your changes.  You're really going to struggle with the suggestions here to use valueList() to generate a list that is then used for a NOT IN(#list here#), because you're likely to have a mighty long list there.  Even proper DBs like Oracle only allow 2000 entries in a list like that (SQL Server is about the same, from memory), so I doubt QoQ will allow even that.  The reason the DBs put limits on these things is that doing a WHERE IN (#list#) is a really poorly-performing process.
    If you've got all your data in the DB, then your query becomes pretty easy, and I'm sure even Access could cope with it.  it'd be something like this:
    SELECT VB.village_id, VB.village_name AS village_old_name, VB.player_id AS player_old_id,
    VU.village_id AS village_new_id, VU.village_name AS village_new_name, VU.player_id as player_new_id
    FROM villages_base VB
    RIGHT OUTER JOIN villages_updates VU
    ON VB.village_id = VU.village_id
    WHERE VB.village_name != VU.village_name
    (that's untested and I only gave it about 1min thought before typing it in, so don't quote me on that!)
    Where VILLAGE_BASE is your original data, and VILLAGE_UPDATES is the data that indicates the changes.  I'm kinda guessing that this is the sort of thing you want.  Note: the "new" villages will be the ones which have NULLs for the village_id, village_old_name and player_old_id.
    Getting all the data into the DB is going to be a matter of looping over the CSV file and doing an INSERT for each row.  And that will take as long as it takes, so you might need to get some control over your request timeouts.  However doing these inserts will take less time than all the QoQ logic suggested before, so you might be OK.  And the query should be quick.
    What happens to the data once the report is written?  Does the "updated" data become the "live" data?  If so, after you run your report you're gonna want to do something like a TRUNCATE on villages_base, and INSERT all the records from villages_update into it (then TRUNCATE villages_update, ready for the next time you need to run this process).  Although don't take my word for it here, as I'm guessing your requirement here ;-)
    Adam

  • Query Help pls dates and logic.

    Hi all gurus
    I have a need where I need to put togahter series of timeline events that occurred in past as a one row concerning dates.
    This is my table .
      CREATE TABLE "SORS"."SOR_TRACKING"
       ( "TRACKING_ID" NUMBER NOT NULL ENABLE,
      "LETTER_ID" NUMBER NOT NULL ENABLE,
      "OFFENDER_ID" NUMBER NOT NULL ENABLE,
      "LOCATION_ID" NUMBER NOT NULL ENABLE,
      "OFFICE_ID" NUMBER,
      "MAIL_DATE" DATE DEFAULT SYSDATE NOT NULL ENABLE,
      "RESPONSE_DATE" DATE,
      "STATUS" VARCHAR2(30 BYTE) DEFAULT 'Mailed',
      "ENTRY_DATE" DATE DEFAULT SYSDATE NOT NULL ENABLE,
      "ENTRY_USER" VARCHAR2(30 BYTE) NOT NULL ENABLE,
      "COMMENTS" VARCHAR2(2000 BYTE),
      "FIRST_NAME" VARCHAR2(80 BYTE) NOT NULL ENABLE,
      "MIDDLE_NAME" VARCHAR2(80 BYTE),
      "LAST_NAME" VARCHAR2(80 BYTE) NOT NULL ENABLE,
      "SIR_NAME" VARCHAR2(30 BYTE),
      "ADDRESS1" VARCHAR2(80 BYTE),
      "ADDRESS2" VARCHAR2(80 BYTE),
      "CITY" VARCHAR2(50 BYTE),
      "STATE" VARCHAR2(30 BYTE),
      "ZIP" VARCHAR2(20 BYTE),
      "COUNTY" VARCHAR2(80 BYTE),
      "OFFENDER_TYPE" VARCHAR2(30 BYTE),
      "LAST_MAIL_DATE" DATE,
      "BATCH_ID" NUMBER NOT NULL ENABLE,
      "JURISDICTION" NUMBER,
      "DL_NAME" VARCHAR2(60 BYTE),
      "DL_OFFICE" VARCHAR2(60 BYTE),
      "DL_ADDRESS" VARCHAR2(60 BYTE),
      "DL_MAILING_ADDRESS" VARCHAR2(60 BYTE),
      "DL_CITY" VARCHAR2(60 BYTE),
      "DL_STATE" VARCHAR2(30 BYTE),
      "DL_ZIP" VARCHAR2(20 BYTE),
      "TITLE" VARCHAR2(10 BYTE),
      "MODIFIED_USER" VARCHAR2(30 BYTE),
      "MODIFIED_DATE" DATE,
      CONSTRAINT "PK_SOR_TRACKING" PRIMARY KEY ("TRACKING_ID"))
    Sample date
    REM INSERTING into SOR_TRACKING
    SET DEFINE OFF;
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (781410,1,4557,110207,2809,to_date('05-NOV-13','DD-MON-RR'),null,'Mailed',to_date('05-NOV-13','DD-MON-RR'),'NEEL',null,'BOB','Jolene','Luna',null,'20535 Valleyview Rd ',null,'Boo','OK','74840','potter','STANDARD',to_date('15-FEB-12','DD-MON-RR'),30211,2809,null,null,null,null,null,null,null,'Ms.','NEEL',to_date('05-NOV-13','DD-MON-RR'));
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (190294,1,4557,110207,2809,to_date('08-FEB-12','DD-MON-RR'),to_date('15-FEB-12','DD-MON-RR'),'Verified',to_date('17-FEB-12','DD-MON-RR'),'Casper',null,'BOB','Jolene','Luna',null,'20535 Valleyview Rd ',null,'Boo','OK','74840','potter','STANDARD',to_date('13-DEC-11','DD-MON-RR'),28442,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (184647,1,4557,110207,2809,to_date('05-DEC-11','DD-MON-RR'),to_date('13-DEC-11','DD-MON-RR'),'Verified',to_date('15-DEC-11','DD-MON-RR'),'Casper',null,'BOB','Jolene','Luna',null,'20535 Valleyview Rd ',null,'Boo','OK','74840','potter','STANDARD',to_date('09-NOV-11','DD-MON-RR'),27985,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (157253,1,4557,102288,2809,to_date('03-FEB-11','DD-MON-RR'),null,'Mailed',to_date('03-FEB-11','DD-MON-RR'),'Casper',null,'BOB','Jolene','Luna',null,'PO Box 146',null,'Boo','OK','74840','potter','STANDARD',to_date('08-NOV-10','DD-MON-RR'),25613,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (149710,1,4557,102288,2809,to_date('01-NOV-10','DD-MON-RR'),to_date('08-NOV-10','DD-MON-RR'),'Verified',to_date('16-NOV-10','DD-MON-RR'),'Casper',null,'BOB','Jolene','Luna',null,'PO Box 146',null,'Boo','OK','74840','potter','STANDARD',to_date('18-OCT-10','DD-MON-RR'),24939,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (138268,1,4557,99564,2809,to_date('03-JUN-10','DD-MON-RR'),to_date('17-JUN-10','DD-MON-RR'),'Letter Returned',to_date('17-JUN-10','DD-MON-RR'),'Boo','Post office: No mail receptacle','BOB','Jolene','Luna',null,'20535 Valley View Rd.',null,'Boo','OK','74840','potter','STANDARD',to_date('19-MAY-10','DD-MON-RR'),24216,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (128798,1,4557,91503,2809,to_date('04-FEB-10','DD-MON-RR'),null,'Mailed',to_date('04-FEB-10','DD-MON-RR'),'Casper',null,'BOB','Jolene','Luna',null,'PO Box 146',null,'Boo','OK','74840','potter','STANDARD',to_date('10-NOV-09','DD-MON-RR'),23369,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (115073,1,4557,91503,2809,to_date('07-AUG-09','DD-MON-RR'),to_date('10-NOV-09','DD-MON-RR'),'Verified',to_date('10-NOV-09','DD-MON-RR'),'Boo',null,'BOB','Jolene','Luna',null,'PO Box 146',null,'Boo','OK','74840','potter','STANDARD',to_date('06-MAY-09','DD-MON-RR'),21926,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (108510,1,4557,91503,2809,to_date('05-MAY-09','DD-MON-RR'),to_date('06-MAY-09','DD-MON-RR'),'Verified',to_date('07-MAY-09','DD-MON-RR'),'Casper',null,'BOB','Jolene','Luna',null,'PO Box 146',null,'Boo','OK','74840','potter','STANDARD',to_date('01-MAY-09','DD-MON-RR'),21316,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (101463,1,4557,88052,2809,to_date('05-FEB-09','DD-MON-RR'),null,'Mailed',to_date('05-FEB-09','DD-MON-RR'),'Boo',null,'BOB','Jolene','Luna',null,'PO Box 146',null,'Boo','OK','74840','potter','STANDARD',to_date('15-DEC-08','DD-MON-RR'),20525,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (97272,1,4557,88052,2809,to_date('05-DEC-08','DD-MON-RR'),to_date('15-DEC-08','DD-MON-RR'),'Verified',to_date('17-DEC-08','DD-MON-RR'),'Casper',null,'BOB','Jolene','Luna',null,'PO Box 146',null,'Boo','OK','74840','potter','STANDARD',to_date('12-NOV-08','DD-MON-RR'),20018,2809,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (68398,1,4557,76399,1070,to_date('10-OCT-07','DD-MON-RR'),to_date('15-NOV-07','DD-MON-RR'),'Letter Returned',to_date('15-NOV-07','DD-MON-RR'),'KERRYMIN','post office: not delivaerable as addressed ','BOB','Jolene','Luna',null,'752 Boo',null,'Norman','OK','73072','Cleveland','STANDARD',to_date('17-MAY-07','DD-MON-RR'),16596,1070,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (63767,1,4557,76399,1070,to_date('09-AUG-07','DD-MON-RR'),to_date('20-AUG-07','DD-MON-RR'),'Letter Returned',to_date('20-AUG-07','DD-MON-RR'),'KERRYMIN','post office: not deliverable as addressed ','BOB','Jolene','Luna',null,'752 Boo',null,'Norman','OK','73072','Cleveland','STANDARD',to_date('17-MAY-07','DD-MON-RR'),16077,1070,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (59499,1,4557,76399,1070,to_date('14-MAY-07','DD-MON-RR'),to_date('17-MAY-07','DD-MON-RR'),'Verified',to_date('17-MAY-07','DD-MON-RR'),'LAWANHAM',null,'BOB','Jolene','Luna',null,'752 Boo',null,'Norman','OK','73072','Cleveland','STANDARD',to_date('14-MAY-07','DD-MON-RR'),15569,1070,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (54783,1,4557,74693,1070,to_date('01-MAR-07','DD-MON-RR'),to_date('06-MAR-07','DD-MON-RR'),'Verified',to_date('13-MAR-07','DD-MON-RR'),'Boo',null,'BOB','Jolene','Luna',null,'1203 Rebecca Lane',null,'Norman','OK','73072','Cleveland','STANDARD',to_date('01-MAR-07','DD-MON-RR'),14994,1070,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (34100,1,4557,58761,1094,to_date('08-FEB-06','DD-MON-RR'),null,'Mailed',to_date('31-MAR-06','DD-MON-RR'),'LAWANHAM','per M. Splawn','BOB','Jolene','Luna',null,'Rt. 1 Box 42',null,'Wewoka','OK','74884','Seminole','STANDARD',to_date('03-FEB-06','DD-MON-RR'),9560,1094,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (27562,1,4557,52781,1115,to_date('08-NOV-05','DD-MON-RR'),null,'Mailed',to_date('08-NOV-05','DD-MON-RR'),'Boo',null,'BOB','Jolene','Luna',null,'5590 Rebel Ridge Rd',null,'El Reno','OK','73036','Canadian','STANDARD',to_date('16-OCT-05','DD-MON-RR'),8034,1115,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (11822,1,4557,39238,1094,to_date('03-MAR-05','DD-MON-RR'),null,'Mailed',to_date('03-MAR-05','DD-MON-RR'),'Boo',null,'BOB','Jolene','Luna',null,'Rt. 1, Box 42',null,'Wewoka','OK','74884','Seminole','STANDARD',to_date('17-FEB-05','DD-MON-RR'),306,null,null,null,null,null,null,null,null,'Ms.',null,null);
    Insert into SOR_TRACKING (TRACKING_ID,LETTER_ID,OFFENDER_ID,LOCATION_ID,OFFICE_ID,MAIL_DATE,RESPONSE_DATE,STATUS,ENTRY_DATE,ENTRY_USER,COMMENTS,FIRST_NAME,MIDDLE_NAME,LAST_NAME,SIR_NAME,ADDRESS1,ADDRESS2,CITY,STATE,ZIP,COUNTY,OFFENDER_TYPE,LAST_MAIL_DATE,BATCH_ID,JURISDICTION,DL_NAME,DL_OFFICE,DL_ADDRESS,DL_MAILING_ADDRESS,DL_CITY,DL_STATE,DL_ZIP,TITLE,MODIFIED_USER,MODIFIED_DATE) values (2257,1,4557,18958,1087,to_date('03-AUG-04','DD-MON-RR'),null,'Mailed',to_date('29-JAN-05','DD-MON-RR'),'SYSTEM',null,'BOB','Jolene','Luna',null,'1037 Tabor Drive',null,'Oklahoma City','OK','73107','Oklahoma',null,null,178,null,null,null,null,null,null,null,null,null,null,null);
    I want to find the all the records whose mail date(earliest of all with no reply) and no response date and find the earlier one with reponse date and display it as a one row.
    For example 
    mail_Date+45 mail_Date in table    earliest date of reponse
    BEGIN_DATE   DEL_DATES           END_DATE                 TRACKING_ID
    17-SEP-04    03-AUG-04 06-          MAR-07                                2257
    Other date and their response date should be shown same way
    The issue is I am not able to retrieve other records in the tables because I am using MIN function.
    here is my query
    SELECT   t.MAIL_DATE + 45 begin_Date,
      del_date.del_dates,
      (SELECT MIN(st2.RESPONSE_DATE) Del_end_date
      FROM sor_tracking st2
      WHERE t.OFFENDER_ID   = st2.OFFENDER_ID
      AND st2.RESPONSE_DATE > del_date.del_dates
      ) End_date,
      t.OFFENDER_ID,
      t.TRACKING_ID
    FROM
      (SELECT MIN(st1.MAIL_DATE) del_dates
        FROM sor_tracking st1
      WHERE st1.OFFENDER_ID  = 4557
      AND st1.RESPONSE_DATE IS NULL
      AND st1.MAIL_DATE      < SysDate - 45
      AND st1.STATUS                  IN ('Letter Returned', 'Mailed')
      AND st1.LETTER_ID               IN (1, 4)
      ) del_date,
      sor_tracking t
    WHERE t.MAIL_DATE   <= del_date.del_dates
    AND (t.OFFENDER_ID   = 4557
         AND t.RESPONSE_DATE IS NULL)
    ORDER BY 1 desc
    Thanks for you time and help.

    with
    sor_tracking as
    (select 4557 offender_id,
            1 letter_id,
            to_date('05-NOV-13','dd-MON-yy') mail_date,
            781410 tracking_id,
            110207 location_id,
            null response_date,
            'Mailed' status
       from dual
    union all
    select 4557,1,to_date('08-FEB-12','dd-MON-yy'),190294,110207,to_date('15-FEB-12','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('05-DEC-11','dd-MON-yy'),184647,110207,to_date('13-DEC-11','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('03-FEB-11','dd-MON-yy'),157253,102288,null,'Mailed' from dual union all
    select 4557,1,to_date('01-NOV-10','dd-MON-yy'),149710,102288,to_date('08-NOV-10','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('03-JUN-10','dd-MON-yy'),138268,99564,to_date('17-JUN-10','dd-MON-yy'),'Letter Returned' from dual union all
    select 4557,1,to_date('04-FEB-10','dd-MON-yy'),128798,91503,null,'Mailed' from dual union all
    select 4557,1,to_date('07-AUG-09','dd-MON-yy'),115073,91503,to_date('10-NOV-09','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('05-MAY-09','dd-MON-yy'),108510,91503,to_date('06-MAY-09','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('05-FEB-09','dd-MON-yy'),101463,88052,null,'Mailed' from dual union all
    select 4557,1,to_date('05-DEC-08','dd-MON-yy'),97272,88052,to_date('15-DEC-08','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('10-OCT-07','dd-MON-yy'),68398,76399,to_date('15-NOV-07','dd-MON-yy'),'Letter Returned' from dual union all
    select 4557,1,to_date('09-AUG-07','dd-MON-yy'),63767,76399,to_date('20-AUG-07','dd-MON-yy'),'Letter Returned' from dual union all
    select 4557,1,to_date('14-MAY-07','dd-MON-yy'),59499,76399,to_date('17-MAY-07','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('01-MAR-07','dd-MON-yy'),54783,74693,to_date('06-MAR-07','dd-MON-yy'),'Verified' from dual union all
    select 4557,1,to_date('08-FEB-06','dd-MON-yy'),34100,58761,null,'Mailed' from dual union all
    select 4557,1,to_date('08-NOV-05','dd-MON-yy'),27562,52781,null,'Mailed' from dual union all
    select 4557,1,to_date('03-MAR-05','dd-MON-yy'),11822,39238,null,'Mailed' from dual union all
    select 4557,1,to_date('03-AUG-04','dd-MON-yy'),2257,18958,null,'Mailed' from dual
    select offender_id,
           letter_id,
           to_char(event_date,'dd-MON-yy') mail_date,
           tracking_id,
           location_id,
           case when last_response_verified is null
                then status
           end status,
           to_char(last_response_verified,'dd-MON-yy') response_date,
           case when last_response_verified is not null
                then 'Verified'
           end response_status
      from (select offender_id,
                   letter_id,
                   event_date,
                   tracking_id,
                   location_id,
                   status,
                   to_find,
                   verified_response,
                   last_value(verified_response ignore nulls) over (partition by offender_id,letter_id
                                                                        order by event_date desc
                                                                   ) last_response_verified
              from (select offender_id,
                           letter_id,
                           event_date,
                           tracking_id,
                           location_id,
                           status,
                           case when event_date < lead(event_date) over (partition by offender_id,letter_id,tracking_id
                                                                             order by event_date
                                                                        ) - 45
                                then 'THIS'
                                when status = 'Mailed'
                                 and lead(tracking_id) over (partition by offender_id,letter_id,tracking_id
                                                                 order by event_date
                                                            ) is null
                                 and direction != lag(direction,1,'null') over (partition by offender_id,letter_id
                                                                                    order by event_date
                                then 'this'
                           end to_find,
                           case when status = 'Verified'
                                then event_date
                           end verified_response
                      from (select offender_id,
                                   letter_id,
                                   mail_date event_date,
                                   tracking_id,
                                   location_id,
                                   'Mailed' status,
                                   'sent' direction
                              from sor_tracking
                            union all
                            select offender_id,
                                   letter_id,
                                   response_date,
                                   tracking_id,
                                   location_id,
                                   status,
                                   'rcvd' direction
                              from sor_tracking
                             where response_date is not null
    where to_find is not null
    order by event_date desc
    OFFENDER_ID
    LETTER_ID
    MAIL_DATE
    TRACKING_ID
    LOCATION_ID
    STATUS
    RESPONSE_DATE
    RESPONSE_STATUS
    4557
    1
    05-NOV-13
    781410
    110207
    Mailed
    4557
    1
    03-FEB-11
    157253
    102288
    13-DEC-11
    Verified
    4557
    1
    04-FEB-10
    128798
    91503
    08-NOV-10
    Verified
    4557
    1
    07-AUG-09
    115073
    91503
    10-NOV-09
    Verified
    4557
    1
    05-FEB-09
    101463
    88052
    06-MAY-09
    Verified
    4557
    1
    03-AUG-04
    2257
    18958
    06-MAR-07
    Verified
    Regards
    Etbin

  • Select query help for Sales order

    Hi Experts,
    I have to write a select query to fetch sales orders which are open along with the quantities which are open ( not delivered). What would the best approach for this?
    Any help is appreciated. Expecting code samples....Thanks
    Thanks
    Ricky

    hi,
    do like this,
    write a select query for vbak and vbuk as follows.
    delivery status field is <b>lfstk</b> from <b>vbuk</b>,
    and relation field is <b>vbeln</b> from the both the tables.
    reward points if useful,
    regards,
    seshu.

  • Content Search web part query

    HI,
    I am struggling to apply filters for one of my query scenario
    1. I have multiple Site Collections http://RootWeb/Sites/Jobs,
    http://RootWeb/Sites/Job1 Etc
        Each site collection has a list with data. One of the column in those lists is Division (Values may be Division 1, Division 2 Etc)
    2. I have another Site Collection http://RootWeb/Sites/Division1
        I am adding a content search web part to display information related to all Job's from Job's list based on Division Site I aam browsing.
    My Issue is I have another application with similar structure.
    How to filter my data so it returnes results data only from my current web app site collection and not another web app site collection?
    kesari suresh

    Hi kesari,
    According to your description, my understanding is that you want to display data only from one site collection in Content Search web part.
    For your issue, you can create a Result Source for the site collection using the query "Path:<URL of the site collection>". The result source only query the date from the site collection. Then you can use the Result Source in the
    Content Search web part, and apply some queries.
    About creating a Result Source, please refer to the link:
    http://technet.microsoft.com/en-us/library/jj683115(v=office.15).aspx
    Best Regards,
    Wendy
    Forum Support
    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]
    Wendy Li
    TechNet Community Support

Maybe you are looking for

  • My adventures with BT- time to change company

    I've seen a few horror stories in the forums and felt like sharing mine. It is a long read, but the plot twists towards the end make it worth the time. It all started when I decided to go with BT in my new flat because the previous tenants had BT so

  • BI Content Administration entries of BO server

    Hi I have installed BI and BO and started integration of BI BO. My question is. i am in middle of process like adding entries in transaction /CRYSTAL/RPTADMIN (Content Administration Workbench). i have given system details and rfc details and also te

  • Import Procurment

    Dear All, I have configured separate pricing procudure, superate Document Type. I have created Import vendor with Vendor currency and custom vendor with INR currency. Now i am creating Purchase order for Import Procurment.In that PO exchange rate wil

  • Oracle9i Enterprise Edition Release 9.2.0.7 downloadable

    Hi, Please let me know where i can i find the downloadable for :Oracle9i Enterprise Edition Release 9.2.0.7 for linux Thank you, -Lokanath.

  • URGENT-Table renderer problem

    I created my own renderer(which renders JCombobox) for JTable.But the problem is when i select an item,it's not setting that item in the combobox.combobox remains blank. but when i click the combobox,it shows that selected item and shows popup menu.