I want sql query for this output

hi guys
could u tell how can i write sql query for this out put
i have one table like this
ID ACCOUTID TAX
1 1 A
2 1 B
3 2 C
4 2 D
5 3 E
7 NULL F
8 NULL G
MY OUT PUT MUST BE LIKE THIS
ID AID TAX
2 1 A
4 2 D
7 NULL F
8 NULL G
HERE IN THIS OUTPUT I SHOULD HAVE
MAXIMAM ID VALUE FOR A REPEATED AID VALUES
AND
THE ROWS AID VALUES IS NULL ALSO MUST PAPULATED IN THE OUTPUT.
I KNOW ONE SOLUTION LIKE THIS
SELECT MAX(ID),AID,TAX
FROM TABLE T
GROUP BY AID,TAX
UNION ALL
SELECT ID, AIC,TAX
FROM TABLE T
WHERE AID IS NULL;
BUT I WANT SAME RESULT WITH OUT USING LOGICAL OPERATORS.
COULD U PLZ TELL A SOL.

Will this help:
SQL> with t as
  2    (
  3      select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
  4      select 2, 1, 'B' from dual union all
  5      select 3, 2, 'C' from dual union all
  6      select 4, 2, 'D' from dual union all
  7      select 5, 3, 'E' from dual union all
  8      select 7, NULL, 'F' from dual union all
  9      select 8, NULL, 'G' from dual
10    )
11  --
12  select id, ACCOUTID AID, Tax
13  from
14  (
15    select t.*
16          ,count(1)       over (partition by t.ACCOUTID) cn
17          ,row_number()   over (partition by t.ACCOUTID order by id desc) rn
18    from t
19  )
20  where cn > 1
21  and (rn = 1 or ACCOUTID is null)
22  /
        ID        AID T
         2          1 B
         4          2 D
         8            G
         7            F
-- If I leave out the OR condition then you'll get this:
SQL> ed
Wrote file afiedt.buf
  1  with t as
  2    (
  3      select 1 ID, 1 ACCOUTID, 'A' TAX from dual union all
  4      select 2, 1, 'B' from dual union all
  5      select 3, 2, 'C' from dual union all
  6      select 4, 2, 'D' from dual union all
  7      select 5, 3, 'E' from dual union all
  8      select 7, NULL, 'F' from dual union all
  9      select 8, NULL, 'G' from dual
10    )
11  --
12  select id, ACCOUTID AID, Tax
13  from
14  (
15    select t.*
16          ,count(1)       over (partition by t.ACCOUTID) cn
17          ,row_number()   over (partition by t.ACCOUTID order by id desc) rn
18    from t
19  )
20  where cn > 1
21* and rn = 1
SQL> /
        ID        AID T
         2          1 B
         4          2 D
         8            G
--which follows the description you've given, but not the output

Similar Messages

  • What can be the SQL Query for this requirement ?

    Hi,
    I have a table with fields like this:
    ID DESC PARENT
    01 ABC 02
    02 ABC1 01
    03 ABC2 01
    04 ABC4 02
    In the above table PARENT column refers to ID column , but actually in SQL query i want to have ID, DESC , and PARENTDESC (i.e., desc value of the corresponding ID)
    Actual output that i need is
    select ID , DESC , ?? from table where ID=someValue . Now if i provide ID=01 then output should be like this:
    ID DESC PARDESC
    01 ABC ABC1
    Can anyone help what can be the required sql query ?
    Edited by: bootstrap on Apr 29, 2011 6:15 AM

    SELECT T1.ID, T1.DESC, T2.DESC
    FROM TABLEA T1, TABLEA T2
    WHERE T1.ID='01'
    AND T2.ID = T1.PARENT;

  • How  to write  a  query  for this output

    I have a string ' if i know good acting , I am a hero '
    now if 'hero' is present in the string it will return ' i am hero' else
    'you are hero'
    How to write a sql query to return the same .

    SQL> select (case
    2 when '&a' like '%hero%' then 'I am hero'
    3 ELSE 'u r hero'
    4 end) output from dual;
    Enter value for a: if i know good acting , I am a hero
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'if i know good acting , I am a hero ' like '%hero%' then 'I am hero'
    OUTPUT
    I am hero
    SQL> /
    Enter value for a: jkhkh
    old 2: when '&a' like '%hero%' then 'I am hero'
    new 2: when 'jkhkh' like '%hero%' then 'I am hero'
    OUTPUT
    u r hero
    Hope this helps.

  • Give me Sql Query for this problem?.  Please Help Me........

    This is my exact requirements
    My PNO table formart is
    PNO PDate PCount
    P001 08/27/05 20
    P001 08/29/05 10
    P002 08/27/05 20
    P003 08/28/05 20
    P003 08/28/05 20
    I want to display the total (PCount) PNumber for this week.
    PNo Sat (27th) Sun(28th) Mon(29th) .........Fri(2/09/2005)
    P001 20 0 10 0
    P002 20 30 0 0
    P003 0 40 0 0
    or at least i want to display, i mean if there is no record for P003 on starturday, it will display 0.
    PNo Sat (27th)
    P001 20
    P002 20
    P003 0
    first iam getting distinct PNo for this week, and check whether these number occurs on saturday if occur then display count otherwise display 0
    Millons of thanks in advance...
    Message was edited by:
    user448874

    EZECASH@ORCL> select * from pno_table;
    PNO  PDATE         PCOUNT
    P001 27-AUG-05         20
    P001 29-AUG-05         10
    P002 27-AUG-05         20
    P003 28-AUG-05         20
    P003 28-AUG-05         20
    P001 02-SEP-05         10
    P001 03-SEP-05         15
    P002 03-SEP-05         10
    P002 04-SEP-05         10
    9 rows selected.
    EZECASH@ORCL> select next_day(trunc(sysdate)-7,'sat') d1,next_day(trunc(sysdate)-7,'sat')+1 d2,next_day(trunc(sysdate)-7,'sat')+2 d3,
      2    next_day(trunc(sysdate)-7,'sat')+3 d4,next_day(trunc(sysdate)-7,'sat')+4 d5,next_day(trunc(sysdate)-7,'sat')+5 d6,
      3    next_day(trunc(sysdate)-7,'sat')+6 d7
      4  from dual
      5  /
    D1        D2        D3        D4        D5        D6        D7
    27-AUG-05 28-AUG-05 29-AUG-05 30-AUG-05 31-AUG-05 01-SEP-05 02-SEP-05
    EZECASH@ORCL> select pno,sum(decode(trunc(pdate),d1,pcount,0)) day1Sum, sum(decode(trunc(pdate),d2,pcount,0)) day2Sum,
      2  sum(decode(trunc(pdate),d3,pcount,0)) day3Sum,sum(decode(trunc(pdate),d4,pcount,0)) day4Sum,
      3  sum(decode(trunc(pdate),d5,pcount,0)) day5Sum,sum(decode(trunc(pdate),d6,pcount,0)) day6Sum,
      4  sum(decode(trunc(pdate),d7,pcount,0)) day7Sum
      5  from  pno_table,
      6  (select next_day(trunc(sysdate)-7,'sat') d1,next_day(trunc(sysdate)-7,'sat')+1 d2,next_day(trunc(sysdate)-7,'sat')+2 d3,
      7    next_day(trunc(sysdate)-7,'sat')+3 d4,next_day(trunc(sysdate)-7,'sat')+4 d5,next_day(trunc(sysdate)-7,'sat')+5 d6,
      8    next_day(trunc(sysdate)-7,'sat')+6 d7
      9  from dual) w
    10  where pdate >= next_day(trunc(sysdate)-7,'sat')
    11  group by pno
    12  /
    PNO     DAY1SUM    DAY2SUM    DAY3SUM    DAY4SUM    DAY5SUM    DAY6SUM    DAY7SUM
    P001         20          0         10          0          0          0         10
    P002         20          0          0          0          0          0          0
    P003          0         40          0          0          0          0          0
    EZECASH@ORCL>

  • How to write a sql query for this condition?

    i have one table with columns v_sub,v_visit and v_date and the structure is like this
    v_sub v_visit v_date
    1 visit-1 01-mar-09
    1 visit-2 05-mar-09
    1 visit-3 17-mar-09
    2 visit-1 04-feb-09
    2 visit-2 12-mar-09
    2 visit-3 20-mar-09
    i want to write a query which check weather it is in chronological order or not.(for v_sub,v_visit and v_date should be in chronological order as above)
    and i want to check the condition as below:
    v_sub v_visit v_date
    1 visit-1 01-mar-09
    1 visit-2 05-feb-09
    1 visit-3 17-mar-09
    2 visit-1 04-feb-09
    2 visit-2 12-jan-09
    2 visit-3 20-mar-09
    Thanks in advance

    use LAG function to get the previous date
    SQL> -- sample data
    SQL> with t
      2  as
      3  (
      4     select 1 v_sub, 'visit-1' v_visit, to_date('01-mar-09','dd-mon-yy') v_date from dual union all
      5     select 1, 'visit-2', to_date('05-mar-09','dd-mon-yy') from dual union all
      6     select 1, 'visit-3', to_date('17-mar-09','dd-mon-yy') from dual union all
      7     select 2, 'visit-1', to_date('04-feb-09','dd-mon-yy') from dual union all
      8     select 2, 'visit-2', to_date('12-mar-09','dd-mon-yy') from dual union all
      9     select 2, 'visit-3', to_date('20-mar-09','dd-mon-yy') from dual
    10  )
    11  -- end of sample data
    12  select v_sub, v_visit, v_date, lag(v_date) over(partition by v_sub order by v_visit, v_date) v_previous_date
    13    from t
    14  /
         V_SUB V_VISIT V_DATE    V_PREVIOU
             1 visit-1 01-MAR-09
             1 visit-2 05-MAR-09 01-MAR-09
             1 visit-3 17-MAR-09 05-MAR-09
             2 visit-1 04-FEB-09
             2 visit-2 12-MAR-09 04-FEB-09
             2 visit-3 20-MAR-09 12-MAR-09
    6 rows selected.Now you can check if the previous_date is less than v_date

  • How can i write sql query for this result ?

    Hello Dear,
    Here is the script first.
    CREATE TABLE ACC_TEST(
    AD_ID NUMBER,
    AD_NAME VARCHAR2(50),
    AD_SPM_ID NUMBER);
    /data are
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (136,'Saleh Ahmed',129);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (142,'Hamidur Rahman',136);
    Insert into ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) values (124,'Jasim Uddin',null);
    INSERT INTO ACC_TEST (AD_ID,AD_NAME,AD_SPM_ID) VALUES (129,'Sazib',124);I Need The Following Result When I Pass A Value Of Ad_Id. For Example I Pass 142 Then Result Should Be
    Select Ad_Id,Ad_Name
    From..
    where ad_id=142
    Ad_Id   Ad_Name
    136     Saleh Ahmed
    129     Sazib
    124     Jasim Uddin
    If I Pass Ad_Id=136 Then Result Should Be
    Ad_Id   Ad_Name
    129     Sazib
    124     Jasim Uddin
    If I Pass Ad_Id=129 Then Result Should Be
    Ad_Id   Ad_Name
    124     Jasim Uddin Database 10G XE
    Any help will be helpful

    Hi,
    HamidHelal wrote:
    WoW ! you acutely got my point. How did you understand that ? lLuck guess. Guessing is usually not the best way to solve problems. It's usually faster and more reliable to say exactly what you want, as well as give an example.
    ittle bit more i want to know, if i want to restrict the output not more then 2, what would be sql ?Now you're not even giviing an example!
    Maybe you want something like this:
    SELECT     ad_id
    ,     ad_name
    FROM     acc_test
    WHERE     LEVEL     BETWEEN 2 AND 3          -- Changed
    START WITH     ad_id     = :target_ad_id
    CONNECT BY     ad_id     = PRIOR ad_spm_id
    ;which will show jsut the parent and the grandparent of the given row.
    I do work with forms developer very much. Sql knowledge is as oracle sql book(cerfitication 9i). But this type of sql isn't available there.
    where can i learn this type of sql ? Different sql then ordinary ?Certification is a different topic entirely.
    There are books and web sites dealing with more advanced techniques. Sorry, I don't know any well enough to recommend them. Some authors (such as Tom Kyte) are consistently good.
    Here are a couple of sites that explain CONNECT BY queries:
    http://www.adp-gmbh.ch/ora/sql/connect_by.html
    http://www.oradev.com/connect_by.jsp

  • What is the sql query for this

    table Employee
    EmpId
    Name
    MonthlySalary
    DateofJoining
    Suggest  a sql server query to find out the employee details whose having salary greater than their yers of experiance 
    nravhad

    Hi ,
      As this seems to be a kind of lab exercise question for learning purpose , i am giving you the pseudo code which will help to solve this problem and learn.
      select <the requeired columns> from employee table.
      where Find the no of years between dateofjoining and current date using DATEDIFF function< monthly salary
      if this is not a lab exercise problem for learning purpose , please forgive my ignorance.
    Best Regards Sorna

  • Please do write sql query for the output in the format

    EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO MAXIMUM_SAL
    7369 SMITH CLERK 7902 17-DEC-80 800 20 3000
    7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 3000
    7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 3000
    7566 JONES MANAGER 7839 02-APR-81 2975 20 3000
    7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30 3000
    maximun salary of the all the employees should be displayed for each row of a employee record.

    WITH L AS (
    SELECT 100 EMPNO, 'RAJESH'  ENAME, 1000 SAL FROM DUAL
    UNION
    SELECT 200 EMPNO, 'VIJAYA'  ENAME, 4000 SAL FROM DUAL
    UNION
    SELECT 300 EMPNO, 'KUMAR'  ENAME, 1200 SAL FROM DUAL
    UNION
    SELECT 400 EMPNO, 'HARI'  ENAME, 100 SAL FROM DUAL
    SELECT empno,  ENAME, SAL, MAX(SAL) OVER()  FROM L;
    EMPNO                  ENAME  SAL                    MAX(SAL)OVER()        
    100                    RAJESH 1000                   4000                  
    200                    VIJAYA 4000                   4000                  
    300                    KUMAR  1200                   4000                  
    400                    HARI   100                    4000                  

  • I need sql query for this plz

    9.     DATA SET (ALIAS TBL)
    SSN     Name     Background Check Date     Review Date
    123456789     Bob Smith     4/15/04     5/10/05
    987654321     Sue Jones     12/2/05     3/4/06
    123456789     Bob Smith     12/31/05     NULL
    REQUIREMENTS
    Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
    EXPECTED RESULTSET
    SSN     Name     Background Check Date     Review Date
    987654321     Sue Jones     12/2/05     3/4/06
    123456789     Bob Smith     12/31/05     NULL

    DATA SET (ALIAS TBL)
    ------------------------------------------------------------------------------------------------------------------|
    SSN     Name     Background Check Date     Review Date|
    -------------------------------------------------------------------------------------------------------------------|
    123456789     Bob Smith     4/15/04     5/10/05
    987654321     Sue Jones     12/2/05     3/4/06
    123456789     Bob Smith     12/31/05     NULL
    REQUIREMENTS
    Write a SQL statement that returns each employee name, their SSN, their most recent background check date, and the corresponding Review Date
    EXPECTED RESULTSET
    SSN      Name     Background CheckDate Review Date
    987654321     Sue Jones     12/2/05     3/4/06
    123456789     Bob Smith     12/31/05     NULL

  • How to form a query for this requirment

    Hi Friends,
    I have a database table in which I store the employee data along with his phone number. Now this row of data can repeat for different phone number depending on if it is office phone or home phone or cell phone.
    But in the output of query, I need name of empoyee and other three columns namely "Home Phone", "Office Phone" and "Cell Phone".
    If employee has three rows for each kind of phone, then in the result of query all three columns for phone numbers should be filled, otherwise as many columns should be filled with data as different phone numbers employee has.
    Can any one please post SQL query for this scenario ?
    Thanks in Adavance

    I cannot imagine, that second and third query are
    under any circumstances faster as first one, but i
    can imagine that they are slower You stated that query without the inline view can only be faster. Did you check on optimizer plans or use tkprof to verify your claim?
    A quick check on those two selects
    SELECT object_id, object_type, object_name
      FROM user_objects;
    SELECT object_id, object_type, object_name
      FROM (SELECT object_id, object_type, object_name
              FROM user_objects)
              ;didn't show any changes in the explain plan unter 10g1.
    C.

  • How to write sql query for counting pairs from below table??

    Below is my SQL table structure.
    user_id | Name | join_side | left_leg | right_leg | Parent_id
    100001 Tinku Left 100002 100003 0
    100002 Harish Left 100004 100005 100001
    100003 Gorav Right 100006 100007 100001
    100004 Prince Left 100008 NULL 100002
    100005 Ajay Right NULL NULL 100002
    100006 Simran Left NULL NULL 100003
    100007 Raman Right NULL NULL 100003
    100008 Vijay Left NULL NULL 100004
    It is a binary table structure.. Every user has to add two per id under him, one is left_leg and second is right_leg... Parent_id is under which user current user is added.. Hope you will be understand..
    I have to write sql query for counting pairs under id "100001". i know there will be important role of parent_id for counting pairs. * what is pair( suppose if any user contains  both left_leg and right_leg id, then it is called pair.)
    I know there are three pairs under id "100001" :-
    1.  100002 and 100003
    2.  100004 and 100005
    3.  100006 and 100007
        100008 will not be counted as pair because it does not have right leg..
     But i dont know how to write sql query for this... Any help will be appreciated... This is my college project... And tommorow is the last date of submission.... Hope anyone will help me...
    Suppose i have to count pair for id '100002'. Then there is only one pair under id '100002'. i.e 100004 and 100005

    Sounds like this to me
    DECLARE @ID int
    SET @ID = 100001--your passed value
    SELECT left_leg,right_leg
    FROM table
    WHERE (user_id = @ID
    OR parent_id = @ID)
    AND left_leg IS NOT NULL
    AND right_leg IS NOT NULL
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • OIM sql Query for getting the status of the task which got failed

    Hi Everyone,
    We have a requirement like we need to get the status of a particular task(say Create User in OID resource - Completed\Rejected status) for the particular user.We are able to get the status of the resource provisioed to the user but not the status of the particular task getting trigerred for the user.can someone put some light on this.We need to get the SQL query for this.
    Thanks in Advance.
    Regards,
    MKN

    Hi
    Use this sample query to get the task status, also check the cooments
    SELECT USR.USR_LOGIN, OSI.SCH_KEY,SCH.SCH_STATUS,STA.STA_BUCKET FROM
    OSI,SCH,STA,MIL,TOS,PKG,OIU,USR,OBJ,OST
    WHERE OSI.MIL_KEY=MIL.MIL_KEY
    AND SCH.SCH_KEY=OSI.SCH_KEY
    AND STA.STA_STATUS=SCH.SCH_STATUS
    AND TOS.PKG_KEY=PKG.PKG_KEY
    AND MIL.TOS_KEY=TOS.TOS_KEY
    AND OIU.USR_KEY=USR.USR_KEY
    AND OIU.OST_KEY=OST.OST_KEY
    AND OST.OBJ_KEY=OBJ.OBJ_KEY
    AND OSI.ORC_KEY=OIU.ORC_KEY
    AND OBJ.OBJ_NAME='AD User'
    AND OST.OST_STATUS = 'Provisioning' -- filter accordinglly
    AND STA.STA_BUCKET = 'Pending' -- filter accordinglly
    AND PKG.PKG_NAME='AD User' -- filter accordinglly
    AND MIL.MIL_NAME='System Validation' ---- filter accordinglly
    Thanks,
    Kuldeep

  • Two or more productid will be accquired by same customerid, by same shipvia, on the same day of the week of shipped date. i want the simple query for this.

    consider this situation,
     Two or more productid will be accquired by same customerid, by same shipvia, on the same  day of the week of shipped date. i want the simple query for this.
    my tables are  from northwind:
    [orders] = OrderID, CustomerID, EmployeeID, OrderDate, RequiredDate, ShippedDate, ShipVia, Freight, ShipName, ShipAddress, ShipCity, ShipRegion, ShipPostalCode, ShipCountry.
    [orders details] = OrderID, ProductID, UnitPrice, Quantity, Discount.
    i tried some but it is not exact, it gives wrong result.
    select pd.CustomerID,pd.ProductID, pd.no_of_time_purchased, sd.ShipVia, sd.same_ship_count, shipped_day from
    select ProductID,o.CustomerID,COUNT(productid) as no_of_time_purchased
    from orders o join [Order Details] od on o.OrderID=od.OrderID group by ProductID,o.CustomerID
    having count(od.ProductID) >1) pd
    join
    (select OrderID,customerid, shipvia, count(shipvia)as same_ship_count, DATENAME(DW,ShippedDate)as shipped_day from orders
    group by customerid, ShipVia, ShippedDate having COUNT(ShipVia) > 1 ) sd
    on sd.CustomerID=pd.CustomerID

    Hi,
    I think I have a solution that will at least give you a clue how to go about it. I have simplified the tables you mentioned and created them as temporary tables on my side, with some fake data to test with. I have incldued the generation of these temporary
    tables for your review.
    In my example I have included:
    1. A customer which has purchased the same product on the same day, using the same ship 3 times,
    2. Another example the same as the first but the third purchase was on a different day
    3. Another example the same as the first but the third purchase was a different product
    4. Another example the same as the first but the third purchase was using a different "ShipVia".
    You should be able to see that by grouping on all of the columns that you wich to return, you should not need to perform any subselects.
    Please let me know if I have missed any requirements.
    Hope this helps:
    CREATE TABLE #ORDERS
     OrderID INT,
     CustomerID INT,
     OrderDate DATETIME,
     ShipVia VARCHAR(5)
    CREATE TABLE #ORDERS_DETAILS
     OrderID INT,
     ProductID INT,
    INSERT INTO #ORDERS
    VALUES
    (1, 1, GETDATE(), 'ABC'),
    (2, 1, GETDATE(), 'ABC'),
    (3, 1, GETDATE(), 'ABC'),
    (4, 2, GETDATE() - 4, 'DEF'),
    (5, 2, GETDATE() - 4, 'DEF'),
    (6, 2, GETDATE() - 5, 'DEF'),
    (7, 3, GETDATE() - 10, 'GHI'),
    (8, 3, GETDATE() - 10, 'GHI'),
    (9, 3, GETDATE() - 10, 'GHI'),
    (10, 4, GETDATE() - 10, 'JKL'),
    (11, 4, GETDATE() - 10, 'JKL'),
    (12, 4, GETDATE() - 10, 'MNO')
    INSERT INTO #ORDERS_DETAILS
    VALUES
    (1, 1),
    (2, 1),
    (3, 1),
    (4, 2),
    (5, 2),
    (6, 2),
    (7, 3),
    (8, 3),
    (9, 4),
    (10, 5),
    (11, 5),
    (12, 5)
    SELECT * FROM #ORDERS
    SELECT * FROM #ORDERS_DETAILS
    SELECT
     O.CustomerID,
     OD.ProductID,
     O.ShipVia,
     COUNT(O.ShipVia),
     DATENAME(DW, O.OrderDate) AS [Shipped Day]
    FROM #ORDERS O
    JOIN #ORDERS_DETAILS OD ON O.orderID = OD.OrderID
    GROUP BY OD.ProductID, O.CustomerID, O.ShipVia, DATENAME(DW, O.OrderDate) HAVING COUNT(OD.ProductID) > 1
    DROP TABLE #ORDERS
    DROP TABLE #ORDERS_DETAILS

  • SQL Query for max values!!

    Hi to all,
    I have four tables
    Tbl_one
    Tbl_two
    Tbl_three
    Tbl_four
    the relation between these tables is
    Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    I want a query like this
    Select tbl_one.com_name, tbl_three.test_date,tbl_four.order_date
    from Tbl_one,Tbl_two,Tbl_three,Tbl_four
    where Tbl_one.SEQ = Tbl_two.SEQ)
    and tbl_two.case_SEQ = Tbl_four.SEQ
    AND Tbl_two.ORDER_SEQ = tbl_three.SEQ))
    and tbl_three.test_date in (select max(test_date) from tbl_three)
    and tbl_four.order_date in select(max(order_date from tbl_for)
    and max(test_date)> Max(order_date)
    any way it is possible?
    the real problem is there are multiple test_dates and
    multiple order_date for same seq in tbl_one.seq.
    eg: -
    name (indian) which has three or more test_date and each test_date have more than one order_date
    indian (name) 01/01/2009(test_date) has ---- 01/10/2009, 01/20/2009 and 01/21/2009) order_dates
    india(name) 02/02/2009 (test_date) has ----- 02/10/2009, 02/20/2009 and 02/30/2009 (order_dates)
    india(name) 03/03/2009 test_date has ----- 03/10/2009, 03/20/2009 , 03/25/2009 (order_dates).
    japan has the same situation and so on
    what i wanted from the query is
    max(test_date)= 03/03/2009 > max(order_date)=03/25/2009
    ans: -
    name
    india(name) 03/03/2009 (test_date) 03/25/2009(order_date)
    etc. etc . etc.
    thanks!!
    Edited by: pl/sql baby on Mar 24, 2009 10:45 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:47 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:51 AM
    Edited by: pl/sql baby on Mar 24, 2009 10:57 AM

    Please use tags either side of code / data (to preserve the formatting and spacing).
    I don't understand your requirement... 03/03/2009 is not greater than 03/25/2009 ?
    Could you please be clearer in your input/output samples and explain more about how to generate the output?                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Error while executing a sql query for select

    HI All,
    ORA-01652: unable to extend temp segment by 128 in tablespace PSTEMP i'm getting this error while i'm executing the sql query for selecting the data.

    I am having 44GB of temp space, while executing the below query my temp space is getting full, Expert please let us know how the issue can be resolved..
    1. I dont want to increase the temp space
    2. I need to tune the query, please provide your recomendations.
    insert /*+APPEND*/ into CST_DSA.HIERARCHY_MISMATCHES
    (REPORT_NUM,REPORT_TYPE,REPORT_DESC,GAP,CARRIED_ITEMS,CARRIED_ITEM_TYPE,NO_OF_ROUTE_OF_CARRIED_ITEM,CARRIED_ITEM_ROUTE_NO,CARRIER_ITEMS,CARRIER_ITEM_TYPE,CARRIED_ITEM_PROTECTION_TYPE,SOURCE_SYSTEM)
    select
    REPORTNUMBER,REPORTTYPE,REPORTDESCRIPTION ,NULL,
    carried_items,carried_item_type,no_of_route_of_carried_item,carried_item_route_no,carrier_items,
    carrier_item_type,carried_item_protection_type,'PACS'
    from
    (select distinct
    c.REPORTNUMBER,c.REPORTTYPE,c.REPORTDESCRIPTION ,NULL,
    a.carried_items,a.carried_item_type,a.no_of_route_of_carried_item,a.carried_item_route_no,a.carrier_items,
    a.carrier_item_type,a.carried_item_protection_type,'PACS'
    from CST_ASIR.HIERARCHY_asir a,CST_DSA.M_PB_CIRCUIT_ROUTING b ,CST_DSA.REPORT_METADATA c
    where a.carrier_item_type in('Connection') and a.carried_item_type in('Service')
    AND a.carrier_items=b.mux
    and c.REPORTNUMBER=(case
    when a.carrier_item_type in ('ServicePackage','Service','Connection') then 10
    else 20
    end)
    and a.carrier_items not in (select carried_items from CST_ASIR.HIERARCHY_asir where carried_item_type in('Connection') ))A
    where not exists
    (select *
    from CST_DSA.HIERARCHY_MISMATCHES B where
    A.REPORTNUMBER=B.REPORT_NUM and
    A.REPORTTYPE=B.REPORT_TYPE and
    A.REPORTDESCRIPTION=B.REPORT_DESC and
    A.CARRIED_ITEMS=B.CARRIED_ITEMS and
    A.CARRIED_ITEM_TYPE=B.CARRIED_ITEM_TYPE and
    A.NO_OF_ROUTE_OF_CARRIED_ITEM=B.NO_OF_ROUTE_OF_CARRIED_ITEM and
    A.CARRIED_ITEM_ROUTE_NO=B.CARRIED_ITEM_ROUTE_NO and
    A.CARRIER_ITEMS=B.CARRIER_ITEMS and
    A.CARRIER_ITEM_TYPE=B.CARRIER_ITEM_TYPE and
    A.CARRIED_ITEM_PROTECTION_TYPE=B.CARRIED_ITEM_PROTECTION_TYPE
    AND B.SOURCE_SYSTEM='PACS'
    Explain Plan
    ==========
    Plan
    INSERT STATEMENT ALL_ROWSCost: 129 Bytes: 1,103 Cardinality: 1                                                        
         20 LOAD AS SELECT CST_DSA.HIERARCHY_MISMATCHES                                                   
              19 PX COORDINATOR                                              
                   18 PX SEND QC (RANDOM) PARALLEL_TO_SERIAL SYS.:TQ10002 :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                         
                        17 NESTED LOOPS PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,103 Cardinality: 1                                    
                             15 HASH JOIN RIGHT ANTI NA PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 129 Bytes: 1,098 Cardinality: 1                               
                                  4 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 63 Bytes: 359,283 Cardinality: 15,621                          
                                       3 PX SEND BROADCAST PARALLEL_TO_PARALLEL SYS.:TQ10001 :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                     
                                            2 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621                
                                                 1 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1001Cost: 63 Bytes: 359,283 Cardinality: 15,621           
                                  14 NESTED LOOPS ANTI PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 40,256,600 Cardinality: 37,448                          
                                       11 HASH JOIN PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 65 Bytes: 6,366,160 Cardinality: 37,448                     
                                            8 BUFFER SORT PARALLEL_COMBINED_WITH_CHILD :Q1002               
                                                 7 PX RECEIVE PARALLEL_COMBINED_WITH_PARENT :Q1002Cost: 1 Bytes: 214 Cardinality: 2           
                                                      6 PX SEND BROADCAST PARALLEL_FROM_SERIAL SYS.:TQ10000 Cost: 1 Bytes: 214 Cardinality: 2      
                                                           5 INDEX FULL SCAN INDEX CST_DSA.IDX$$_06EF0005 Cost: 1 Bytes: 214 Cardinality: 2
                                            10 PX BLOCK ITERATOR PARALLEL_COMBINED_WITH_CHILD :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448                
                                                 9 MAT_VIEW ACCESS FULL MAT_VIEW PARALLEL_COMBINED_WITH_PARENT CST_ASIR.HIERARCHY :Q1002Cost: 63 Bytes: 2,359,224 Cardinality: 37,448           
                                       13 TABLE ACCESS BY INDEX ROWID TABLE PARALLEL_COMBINED_WITH_PARENT CST_DSA.HIERARCHY_MISMATCHES :Q1002Cost: 0 Bytes: 905 Cardinality: 1                     
                                            12 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT SYS.HIERARCHY_MISMATCHES_IDX3 :Q1002Cost: 0 Cardinality: 1                
                             16 INDEX RANGE SCAN INDEX PARALLEL_COMBINED_WITH_PARENT CST_DSA.IDX$$_06EF0001 :Q1002Cost: 1 Bytes: 5 Cardinality: 1

Maybe you are looking for