Sql query  - urgent major problem

If I have the following sql query and I would like to perform a select on this how would I do it.
select StudentNo, CourseCode, Year, ExamMark from **
where CourseCode='ELE304' AND Year=1999;
**select COURSESTUDENT.StudentNo, COURSESTUDENT.CourseCode, COURSESTUDENT.Year, MARKS.ExamMark, MARKS.EntryNo AS RESULT FROM
COURSESTUDENT LEFT JOIN MARKS ON COURSESTUDENT.StudentNo=MARKS.StudentNo AND COURSESTUDENT.CourseCode='ELE304' AND
MARKS.CourseCode='ELE304' AND COURSESTUDENT.Year=1999 AND MARKS.Year=1999;

Ive been trying to get this sql query correct the whole day this is a joke .......
Someone must know what the prob is...
thanks
tzaf

Similar Messages

  • Need SQL Query ---Urgent

    Hi Gurus,
    Select * from xxa_test1
    invoice_type || LOC_CODE|| seq_no
    =========================
    DOMESTIC     A     1
    DOMESTIC     B     2
    DOMESTIC     C     3
    Select * from xxa_test2
    cust_no || cust_name || loc_code
    =======================
    1001 Test B
    1001 Test C
    The Requirement is i want sql query to retrive only one record based on seq no if suppose 2 records retrive in that
    B is having seqno 2 and c having seq no 3
    that sql query should return only one record which is having min seq no. for example in that B, C only B record should return.
    If multiple values returned then the program must check based on the seq no it should take min seq no.
    i have written this query
    Select *
    from xxa_test2 t2
    where t2.loc_code in (select t1.loc_code
    from xxa_test1 t1
    order by Seq_no
    where above query is correct or not , i am getting problem with this query.
    Please let me know its very urgent
    Thanks
    Manju
    Edited by: venu on Jul 26, 2011 12:50 AM

    Something like:
    SELECT cust_no, cust_name, loc_code
    FROM
    (with xxa_test1
    as (SELECT 'DOMESTIC' invoice_type, 'A' loc_code, 1 seq_no FROM dual
    union all
    SELECT 'DOMESTIC', 'B', 2 FROM dual
    union all
    SELECT 'DOMESTIC', 'C', 3 FROM dual),
    xxa_test2
    as (SELECT 1001 cust_no, 'Test' cust_name, 'B' loc_code FROM dual
    union all
    SELECT 1001 , 'Test' , 'C' FROM dual)
    SELECT cust_no, cust_name, t2.loc_code, seq_no, min(seq_no) over() min_seq
    FROM xxa_test2 t2,xxa_test1 t1
    WHERE t2.loc_code = t1.loc_code)
    WHERE seq_no = min_seq
    SQL> /
       CUST_NO CUST L
          1001 Test B

  • Help me write a SQL query; urgent

    Hi, can somebody please help me write a SQL query.
    I have 3 tables each with the same column names (Col1, Col2, Col3). Col1 is PK with Unique Constraint.
    I wanted to add values of Col2 and Col3 (from all 3 tables) and put it in a separate table (i.e aggregated) of all values found in Col1.
    Does anybody help me please ?
    thanks alot.

    Please don't mark your question as urgent. You've been around here long enough that you should know that it will not get your question anwered any faster, and may just irritate people into not answering at all.
    I'm not sure exactly what you want.
    Are you saying you want t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3 for the rows that have the same c1 in all three tables?
    If so, it would be like this, I think: insert into t4
    select t1.c1
    , t1.c2 + t1.c3 + t2.c2 + t2.c3+ t3.c2 + t3.c3
    from t1, t2, t3
    where t2.c1 = t1.c1
    and t3.c1 = t1.c1If that's not what you want, please clarify.
    And next time maybe you should post your SQL question in a SQL forum.

  • Need sql query or pl/sql query urgent

    Hi Experts,
    The requirement is that
    SELECT 'N' flag, sysdate init_date,
    '' vendor_name,
    DECODE (pa.address_type,
    'P', 'Present Address',
    'R', 'Permanent Address',
    pa.address_type
    ) address_type,
    pa.address_line1
    || ','
    || pa.address_line2
    || ','
    || pa.town_or_city
    || ','
    || meaning
    || ','
    || pa.POSTAL_CODE "Address",
    TRUNC (TO_CHAR (pa.date_from, 'YYYY')) YEAR,
    TO_CHAR (pa.date_from, 'MON') MONTH,''station
    FROM per_addresses pa, fnd_lookup_values, per_all_people_f pf
    WHERE (pf.employee_number = :1 or pf.APPLICANT_NUMBER = :2)
    and pf.EFFECTIVE_END_DATE='31-DEC-4712'
    AND pa.person_id = pf.person_id
    AND pa.business_group_id = 42
    --AND pa.date_to IS NULL
    AND lookup_type = 'PER_US_COUNTRY_CODE'
    AND lookup_code = pa.country
    AND enabled_flag = 'Y'
    AND (end_date_active IS NULL OR end_date_active > SYSDATE)
    if i run the above query the output is coming like that
    Present Address |     Flat No. 1201, OC - 15, Orange County, Plot No. GH - 4,Ahinsa Khand 1st, Indrapuram,Ghaziabad,India,201010|     2,010|     JUL
    Permanent Address |     Q.No. 354, Sector - 3 / B,,Bokaro Steel City,India,827003     |2,010     |JUL
    Present Address |     4, Sitara,Chandra Reddy layout, S.T. Bed,Bangalore,India,0|     2,006|     JAN
    Present Address |     101,,Ushma Urja Apartments,Noida,India,201301 |     2,006 |     JUL
    Permanent Address |     F-19, Maccon Colony, Opp. DAV Shyamali School,,Ranchi,India,834002 |     2,009 |     FEB
    Present Address |     Flat no. 604, B - 1, Krishna Apra Gardens,Vaibhav Khand, Plot - 7,Ghaziabad,India,201010 |     2,009     FEB
    But the requirement is the output should come like that
    Permanent Address     |Q.No. 354, Sector - 3 / B,,Bokaro Steel City,India,827003|     2,010     |JUL                    
    Permanent Address 1|     F-19, Maccon Colony, Opp. DAV Shyamali School,,Ranchi,India,834002|     2,009 |     FEB
    Present Address |     Flat No. 1201, OC - 15, Orange County, Plot No. GH - 4,Ahinsa Khand 1st, Indrapuram,Ghaziabad,India,201010|     2,010 |     JUL                    
    Present Address 1 |     Flat no. 604, B - 1, Krishna Apra Gardens,Vaibhav Khand, Plot - 7,Ghaziabad,India,201010|     2,009 |     FEB                    
    Present Address 2 |     101,,Ushma Urja Apartments,Noida,India,201301|     2,006|     JUL     
    Present Address 3 |     4, Sitara,Chandra Reddy layout, S.T. Bed,Bangalore,India,0 |     2,006|     JAN     
    Please provide logice how i need to write a sql query or procedure or function or package
    Thanks & Regards
    Venu

    You can use analytics here :
    SELECT
        flag,
        init_date,
        vendor_name,
        address_type   ||' ' ||rn AS address_type,
        Address,
        YEAR,
        MONTH,
        station
    FROM
            SELECT
                'N' flag,
                sysdate init_date,
                '' vendor_name,
                DECODE (pa.address_type, 'P', 'Present Address', 'R','Permanent Address', pa.address_type ) address_type,
                row_number() over(partition BY pa.address_type order by 1) AS rn,
                pa.address_line1
                || ','
                || pa.address_line2
                || ','
                || pa.town_or_city
                || ','
                || meaning
                || ','
                || pa.POSTAL_CODE "Address",
                TRUNC (TO_CHAR (pa.date_from, 'YYYY')) YEAR,
                TO_CHAR (pa.date_from, 'MON') MONTH,
                '' station
            FROM
                per_addresses pa,
                fnd_lookup_values,
                per_all_people_f pf
            WHERE
                    pf.employee_number  = :1
                 OR pf.APPLICANT_NUMBER = :2
            AND pf.EFFECTIVE_END_DATE='31-DEC-4712'
            AND pa.person_id         = pf.person_id
            AND pa.business_group_id = 42
                --AND pa.date_to IS NULL
            AND lookup_type  = 'PER_US_COUNTRY_CODE'
            AND lookup_code  = pa.country
            AND enabled_flag = 'Y'
            AND
                    end_date_active IS NULL
                 OR end_date_active  > SYSDATE
        );

  • In line SQL Query - Urgent

    In the problem iam calculating a Stock report.In the SQL suppose the relation F does not return any rows , then (D.ACC_QTY + F.RET_QTY) gives null. How to avoid this problem..
    SELECT A.CLASSIFICATION_CODE, A.ITEM_ABBR, A.ITEM_DESC,
    A.ALT_ITEM_CODE, A.UOM_DESC, A.BASIC_PRICE,
    (A.OPENING_QTY + B.ACC_QTY - C.ISS_QTY)
    OPENING_STOCK, (D.ACC_QTY + F.RET_QTY) ACCEPT_QTY, E.ISS_QTY,
    ((A.OPENING_QTY + B.ACC_QTY - C.ISS_QTY)
    + (D.ACC_QTY + F.RET_QTY) - E.ISS_QTY)
    QTY_IN_HAND
    FROM (SELECT CLASSIFICATION_CODE, ITEM_ABBR, ITEM_DESC,
    ALT_ITEM_CODE, NVL(OPENING_QTY, 0)
    OPENING_QTY, UOM_MASTER.UOM_DESC,
    BASIC_PRICE
    FROM ITEM_MASTER, UOM_MASTER
    WHERE ITEM_MASTER.UOM_CODE = UOM_MASTER.UOM_CODE)
    A,
    (SELECT GRN_DETAIL.ITEM_CODE,
    SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
    ACC_QTY
    FROM GRN_HEADER, GRN_DETAIL
    WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
    GRN_HEADER.GRN_DATE < '01-JAN-2006'
    GROUP BY GRN_DETAIL.ITEM_CODE) B,
    (SELECT MRN_DETAIL.ITEM_CODE,
    SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
    ISS_QTY
    FROM MRN_HEADER, MRN_DETAIL
    WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
    MRN_HEADER.MRN_DATE < '01-JAN-2006'
    GROUP BY MRN_DETAIL.ITEM_CODE) C,
    (SELECT GRN_DETAIL.ITEM_CODE,
    SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
    ACC_QTY
    FROM GRN_HEADER, GRN_DETAIL
    WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
    GRN_HEADER.GRN_DATE BETWEEN
    '01-JAN-2006' AND '31-DEC-2006'
    GROUP BY GRN_DETAIL.ITEM_CODE) D,
    (SELECT MRN_DETAIL.ITEM_CODE,
    SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
    ISS_QTY
    FROM MRN_HEADER, MRN_DETAIL
    WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
    MRN_HEADER.MRN_DATE BETWEEN
    '01-JAN-2006' AND '31-DEC-2006'
    GROUP BY MRN_DETAIL.ITEM_CODE) E,
         (SELECT B.ITEM_CODE,
    SUM(NVL(B.QUANTITY_ISSUE,0))
    RET_QTY
    FROM MATERIAL_MOVEMENT_HEADER A,MATERIAL_MOVEMENT_DETAIL B
    WHERE A.SLIP_NO = B.SLIP_NO AND
    A.SLIP_DATE BETWEEN
    '01-JAN-2006' AND '31-DEC-2006' AND
              B.TO_JOB_CODE IS NULL
    GROUP BY B.ITEM_CODE) F
    WHERE A.ALT_ITEM_CODE = B.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = C.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = D.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = E.ITEM_CODE (+) AND
         A.ALT_ITEM_CODE = F.ITEM_CODE (+) AND
         A.ALT_ITEM_CODE LIKE 'BOBRNG%017' AND
    A.CLASSIFICATION_CODE = 'BO';

    Sorry members for writing the word 'Urgent'..and really cutting down on your work.
    I am thankful to the person who pointed out my error in the query..it was really simple..should hv solved myself, but even after changing the query with Nvl and changing the business logic to some extent it again fetches no rows..
    The sql given underneath is basically a job-wise stock allocation report..
    SELECT B.JOB_CODE, A.CLASSIFICATION_CODE, A.ITEM_ABBR,
    A.ITEM_DESC, A.ALT_ITEM_CODE, A.UOM_DESC,
    A.BASIC_PRICE, (A.OPENING_QTY + (NVL(B.ACC_QTY, 0)
    + NVL(F.RET_IN, 0)) - (NVL(C.ISS_QTY, 0) + NVL(G.RET_OUT,
    0))) AS OPENING_STOCK, (NVL(D.ACC_QTY, 0)
    + NVL(H.RET_IN, 0)) RECEIVED, (NVL(E.ISS_QTY, 0)
    + NVL(I.RET_OUT, 0)) ISSUED,
    ((A.OPENING_QTY + (NVL(B.ACC_QTY, 0) + NVL(F.RET_IN, 0))
    - (NVL(C.ISS_QTY, 0) + NVL(G.RET_OUT, 0)))
    + (NVL(D.ACC_QTY, 0) + NVL(H.RET_IN, 0)) - (NVL(E.ISS_QTY,
    0) + NVL(I.RET_OUT, 0))) QTY_IN_HAND
    FROM (SELECT CLASSIFICATION_CODE, ITEM_ABBR, ITEM_DESC,
    ALT_ITEM_CODE, UOM_MASTER.UOM_DESC,
    BASIC_PRICE, 0 OPENING_QTY
    FROM ITEM_MASTER, UOM_MASTER
    WHERE ITEM_MASTER.UOM_CODE = UOM_MASTER.UOM_CODE)
    A,
    (SELECT GRN_HEADER.JOB_CODE,
    GRN_DETAIL.ITEM_CODE,
    SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
    ACC_QTY
    FROM GRN_HEADER, GRN_DETAIL
    WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
    GRN_HEADER.GRN_DATE < '01-JAN-2006'
    GROUP BY GRN_HEADER.JOB_CODE,
    GRN_DETAIL.ITEM_CODE) B,
    (SELECT B.TO_JOB_CODE, B.ITEM_CODE,
    SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_IN
    FROM MATERIAL_MOVEMENT_HEADER A,
    MATERIAL_MOVEMENT_DETAIL B
    WHERE A.SLIP_NO = B.SLIP_NO AND
    A.SLIP_DATE < '01-JAN-2006'
    GROUP BY B.TO_JOB_CODE, B.ITEM_CODE) F,
    (SELECT MRN_HEADER.JOB_CODE,
    MRN_DETAIL.ITEM_CODE,
    SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
    ISS_QTY
    FROM MRN_HEADER, MRN_DETAIL
    WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
    MRN_HEADER.MRN_DATE < '01-JAN-2006'
    GROUP BY MRN_HEADER.JOB_CODE,
    MRN_DETAIL.ITEM_CODE) C,
    (SELECT B.JOB_CODE, B.ITEM_CODE,
    SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_OUT
    FROM MATERIAL_MOVEMENT_HEADER A,
    MATERIAL_MOVEMENT_DETAIL B
    WHERE A.SLIP_NO = B.SLIP_NO AND
    A.SLIP_DATE < '01-JAN-2006'
    GROUP BY B.JOB_CODE, B.ITEM_CODE) G,
    (SELECT GRN_HEADER.JOB_CODE,
    GRN_DETAIL.ITEM_CODE,
    SUM(NVL(GRN_DETAIL.ACCEPT_QTY, 0))
    ACC_QTY
    FROM GRN_HEADER, GRN_DETAIL
    WHERE GRN_HEADER.GRN_NO = GRN_DETAIL.GRN_NO AND
    GRN_HEADER.GRN_DATE BETWEEN
    '01-JAN-2006' AND '31-DEC-2006'
    GROUP BY GRN_HEADER.JOB_CODE,
    GRN_DETAIL.ITEM_CODE) D,
    (SELECT B.TO_JOB_CODE, B.ITEM_CODE,
    SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_IN
    FROM MATERIAL_MOVEMENT_HEADER A,
    MATERIAL_MOVEMENT_DETAIL B
    WHERE A.SLIP_NO = B.SLIP_NO AND
    A.SLIP_DATE BETWEEN '01-JAN-2006' AND
    '31-DEC-2006'
    GROUP BY B.TO_JOB_CODE, B.ITEM_CODE) H,
    (SELECT MRN_HEADER.JOB_CODE,
    MRN_DETAIL.ITEM_CODE,
    SUM(NVL(MRN_DETAIL.ISSUED_QTY, 0))
    ISS_QTY
    FROM MRN_HEADER, MRN_DETAIL
    WHERE MRN_HEADER.MRN_NO = MRN_DETAIL.MRN_NO AND
    MRN_HEADER.MRN_DATE BETWEEN
    '01-JAN-2006' AND '31-DEC-2006'
    GROUP BY MRN_HEADER.JOB_CODE,
    MRN_DETAIL.ITEM_CODE) E,
    (SELECT B.JOB_CODE, B.ITEM_CODE,
    SUM(NVL(B.QUANTITY_ISSUE, 0)) RET_OUT
    FROM MATERIAL_MOVEMENT_HEADER A,
    MATERIAL_MOVEMENT_DETAIL B
    WHERE A.SLIP_NO = B.SLIP_NO AND
    A.SLIP_DATE BETWEEN '01-JAN-2006' AND
    '31-DEC-2006'
    GROUP BY B.JOB_CODE, B.ITEM_CODE) I
    WHERE A.ALT_ITEM_CODE = B.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = C.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = D.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = E.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = F.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = G.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = H.ITEM_CODE (+) AND
    A.ALT_ITEM_CODE = I.ITEM_CODE (+) AND
    B.JOB_CODE = C.JOB_CODE AND
    B.JOB_CODE = D.JOB_CODE AND
    B.JOB_CODE = E.JOB_CODE AND
    B.JOB_CODE = F.TO_JOB_CODE AND
    B.JOB_CODE = G.JOB_CODE AND
    B.JOB_CODE = H.TO_JOB_CODE AND
    B.JOB_CODE = I.JOB_CODE AND
    A.ALT_ITEM_CODE = 'BOSNVL0004-006-002';
    regards,

  • Need a SQL Query (URGENT)

    Hi Folks,
    I have 2 tables, in which the 1st one has 200 columns and 2 table had 2 columns.. There is one common column for both the tables, but there is little change in schema of the tables...The common col in 2nd table is a primary key but the same column in the 1st table is a ordinary one..The data type for the common column is same...
    Now i need to write a query to select 199columns(except the common column)from the 1st table and the other column(2nd col)other than the common column frm the 2nd table for "table1.commoncolumn=table2.commoncolumn"......
    I had tried the natural join but its nt working in my informix sql database....I also tried by explicitly mentioning column names like "select column1,column2....column199,table2.column2 from table1,table2 where table1.commoncolumn=table2.commoncolumn", but its having a severe performance impact.......
    Can some please suggest a query for the above one?? Thankx in advance..

    Please gimme possible solutions & suggestions regarding the above query....
    The informix z forum very slow...The problem is, you labeled your questions badly. As this is a forum of volunteers people tend to react badly to the use of the word "urgent" in the subject line. Nobody's question matters more than anybody else's. In fact some regulars won't answer questions with "urgent" in the strapline as a matter of principle.
    Then when we get to actually read your question it turns out to be a question about Informix. I guess not many people here use Informix so your potential pool of responders is pretty small (for instance I'm not even sure how to spell it).
    It's not our fault the Informix forums are so lame.
    Anyway, what I suggest is you repost your question with a new title: (Off topic) Need help with an INFORMIX query.
    At least that will attract people who might be able to answer your question. Then you need to include the actual query you're running and all the supporting details necessary for people to understand the nature of the performance impact.
    You need to ask the right people and you need to ask the right question. This is standard etiquette (and indeed common sense) regardless of which forum you're using.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • Sql query-urgent

    I would be thankful if anyone could please advise on the sql question as follows:
    id1,dept1,JOHN,12-12-1991
    id2,dept1,JOHN,12-12-1992
    id3,dept1,JOHN,12-12-1993
    id4,dept1,SMITH,11-10-1994
    id5,dept1,SMITH,12-12-1995
    id6,dept1,SMITH,12-12-1996
    id7,dept1,CHRIS,07-07-1997
    id8,dept1,CHRIS,12-12-1998
    I need a query to get the the data when a particular employee was replaced
    as follows:
    name,date_replaced
    JOHN,11-10-1993
    SMITH,07-07-1997
    CHRIS,null
    Any suggestions are most welcome.

      1  select distinct name, last_value(NextHired) over (ORDER BY dept,name)
      2  from
      3  (with emp as
      4    (select 'id1' id,
      5            'dept1' dept,
      6            'JOHN' name,
      7            to_date('12-12-1991' ,'DD-MM-YYYY') hiredate from dual
      8     union
      9     select 'id2','dept1','JOHN',to_date('12-12-1992' ,'DD-MM-YYYY') from dual
    10     union
    11     select 'id3','dept1','JOHN',to_date('12-12-1993' ,'DD-MM-YYYY') from dual
    12     union
    13     select 'id4','dept1','SMITH',to_date('11-10-1994','DD-MM-YYYY') from dual
    14     union
    15     select 'id5','dept1','SMITH',to_date('12-12-1995','DD-MM-YYYY') from dual
    16     union
    17     select 'id6','dept1','SMITH',to_date('12-12-1996','DD-MM-YYYY') from dual
    18     union
    19     select 'id7','dept1','CHRIS',to_date('07-07-1997','DD-MM-YYYY') from dual
    20     union
    21     select 'id8','dept1','CHRIS',to_date('12-12-1998','DD-MM-YYYY') from dual)
    22  select id,name, dept,lead (hiredate,1) OVER (ORDER BY hiredate) AS NextHired
    23  from   emp
    24  order by id, dept)
    25* order by last_value(NextHired) over (ORDER BY dept,name)
    SQL> /
    JOHN  11/10/94
    SMITH 07/07/97
    CHRIS
    SQL> Nicolas.
    Message was edited by:
    N. Gasparotto
    Hmm, rajeevm, you wrote JOHN,11-10-1993, but it seems it's a mistake... isn't it ?

  • SQL Query Urgent..pls help

    Dear Experts,
    Table.
    C_id Purity
    1     100
    2     100
    10     100
    11     100
    12     100
    Ranking Regions by Size You have to list all regions in the table, and you have to list them according to their size.
    you need to list all regions of two or more containers with a purity of 100, and you need to sort that list by the number of containers in each region.
    The output should be something like this:
    RegBeg RegEnd RegionSize
    10 12 3
    1 2 2
    Kindly help me,
    Basav

    Looks like a homework assignment.
    Perhaps you can explain to your tutor how the tabbibitosan method works...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 1 as C_id, 100 as Purity from dual union all
      2             select 2, 100 from dual union all
      3             select 4, 100 from dual union all
      4             select 5, 100 from dual union all
      5             select 6, 50 from dual union all
      6             select 7, 100 from dual union all
      7             select 10, 100 from dual union all
      8             select 11, 100 from dual union all
      9             select 12, 100 from dual)
    10  --
    11  -- use tabbibitosan method to group data
    12  select min(c_id) as min_c_id
    13        ,max(c_id) as max_c_id
    14        ,count(*) as grp_size
    15  from   t
    16  where purity = 100
    17  group by c_id-rownum
    18  having count(*) > 1
    19* order by 3 desc, 1
    SQL> /
      MIN_C_ID   MAX_C_ID   GRP_SIZE
            10         12          3
             1          2          2
             4          5          2... if you can understand it. ;)

  • SQL QUERY, URGENT PLEASE HELP .....

    Hi,
    There is a table which stores the sales record, weekly basis.
    For example
    WEEK______ ITEMNO______SALES______QTY
    200201_____10001______10,000______50
    200202_____10001______18,000______55
    200230_____10001______55,000_____330
    Now the report should display the week nos and a Cumulative average.
    like
    ITEM NO - 10001
    WEEKNO____WK-AVG____13WK-AVG____26WK-AVG____52WK-AVG
    200201
    200202
    200203
    200230
    The WK-AVG is calculated for that perticular (weeks sales /weeks qty) but for 13WK-AVG,26-AVG and 52WK-AVG , The calculationis the (cumulative of last 13 week sales /cumulative of last 13 wk qty)
    for example at week 200230 the 13WK-AVG should be
    (cumulative sales from week 200218 to 200230 / cumulative qty from week 200218 to 200230 )
    the same hold good for 26WK-AVG AND 52WK-AVG. Please suggest me how to do it . This is very urgent . Please help me .
    Thanks
    Feroz

    Feroz,
    One way is to use subselects. E.g.,
    SELECT WK_AVG, 13WK_AVG, 26WK_AVG, 56WK_AVG FROM
    (SELECT (SALES/QTY) AS WK_AVG FROM TABLE WHERE ITEMNO=x AND WEEK = ...),
    (SELECT (SUM(SALES)/SUM(QTY)) AS 13WK_AVG WHERE ITEMNO=X AND WEEK > Y AND WEEK <= Z),
    hope this helps.
    regards,
    Stewart

  • SQL query urgent helps needed!!!

    Hi all,
    I got the following query :-
    SELECT RH.REQUEST_NUMBER,     
         MSIK.CONCATENATED_SEGMENTS,
    MSIK.DESCRIPTION,
         RL.FROM_SUBINVENTORY_CODE,
         RL.UOM_CODE,
         RL.QUANTITY,
    PP.FULL_NAME     ,
         M.TRANSACTION_QUANTITY
    FROM     MTL_TXN_REQUEST_HEADERS RH,
    MTL_TXN_REQUEST_LINES RL,
         MTL_SYSTEM_ITEMS_KFV MSIK,
    FND_USER FU,
    PER_PEOPLE_V7 PP,
              ( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE, SUM(MOQ.TRANSACTION_QUANTITY)
              FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
              WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
              AND MSIK2.ORGANIZATION_ID = 8
              AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
              GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
    WHERE     
    RH.HEADER_STATUS IN(3,7,8)
    AND RH.MOVE_ORDER_TYPE IN(1,2)
    and rh.header_id = rl.header_id
    AND MSIK.INVENTORY_ITEM_ID = RL.INVENTORY_ITEM_ID
    AND MSIK.ORGANIZATION_ID = 8
    AND RL.FROM_SUBINVENTORY_CODE LIKE 'ST%'
    AND RH.CREATED_BY = FU.USER_ID
    AND FU.EMPLOYEE_ID = PP.PERSON_ID
    However, when I try to run I got the invalid column for m.transaction_quantity ??? why? does it b'cos of the group sum that I used ?
    My intention of this query to display the sum of total qty from the mtl_onhand_quantities table.
    Please helps.
    Thanks.
    Rgds
    Lim

    sorry if its too late.....
    my guess is alias the SUM(MOQ.TRANSACTION_QUANTITY) in the sub-query table (M) as TRANSACTION_QUANTITY.
    -------- code snippet---------
    FND_USER FU,
    PER_PEOPLE_V7 PP,
    ( SELECT MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE,
    SUM(MOQ.TRANSACTION_QUANTITY) TRANSACTION_QUANTITY <------------------------------------This is important
    FROM MTL_ONHAND_QUANTITIES MOQ, MTL_SYSTEM_ITEMS_KFV MSIK2
    WHERE MSIK2.INVENTORY_ITEM_ID = MOQ.INVENTORY_ITEM_ID
    AND MSIK2.ORGANIZATION_ID = 8
    AND MOQ.SUBINVENTORY_CODE LIKE 'ST%'
    GROUP BY MSIK2.CONCATENATED_SEGMENTS, MOQ.SUBINVENTORY_CODE) M
    WHERE
    RH.HEADER_STATUS IN(3,7,8)
    AND RH.MOVE_ORDER_TYPE IN(1,2)
    --------------code snippet ends------------------------
    hope this helps,

  • T sql query urgent pls

    hi ,
    i have data like this
    cola colb colc
    123 12 a
    123 12  b
    123 12 a
    124 12  d
    124 12  f
    we have to loop throuhj all the values associated with colc for each cola and colb, if all the values are not in (a and b), then i return the distinct on cola  and colb
    in the above instnace , the retruned value is 124 12, since none of the values in colc are in (a and b)
    pls help, tx

    Please see below...
    DECLARE @TABLE TABLE
    (cola INT, colb INT, colc CHAR(10))
    INSERT INTO @TABLE VALUES(123, 12, 'a'), (123, 12, 'b'), (123, 12, 'a')
    , (124, 12, 'd'), (124, 12, 'f'), (123, 12, 'c')
    SELECT * FROM @TABLE b WHERE b.colc = 'a' OR b.colc = 'b'
    ;WITH CTE AS
    (SELECT DISTINCT cola, colb FROM @TABLE b WHERE b.colc = 'a' OR b.colc = 'b')
    SELECT DISTINCT a.cola, a.colb
    FROM @TABLE a
    LEFT JOIN CTE b ON a.cola = b.cola AND a.colb = b.colb
    WHERE b.cola IS NULL AND b.colb IS NULL
    Please mark as answer, if this has answered your question.
    Good Luck :) .. visit www.sqlsaga.com for more t-sql code snippets and BI related how to articles.

  • 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>

  • SQL Query of an OWB map (row based)

    If I trace a session, execute an OWB map (row based), will the trace file contain the actual SQL query ?
    The problem with me is that when I am executing this row -based OWB map, it is throwing me an error CursorFetchMapTerminationRTV20007 BUT ( plus taking a long time) when I am taking out the intermediate SQL insert query,it is working fine ( and also within a very short period of time)
    Execution status = COMPLETE
    message text = ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    message text = CursorFetchMapTerminationRTV20007
    No. task errors = 0
    No. task warnings = 2
    No. errors = 1
    Since this OWB map (Truncate Insert)  is row based hence I cannot cannot get the back end query from the OWB generated pl/sql package so wondering if I trace the session, check the trace file, may be I will able to see the exact SQL query generated. But wanted to confirm the same.

    Yes, the actual SQL run in the session will be in the trace file.

  • VERY URGENT: problem in sql query with long datatype in weblogic

    I have a problem while tryind to retrieve a column value with a long datatype using servlet and oci driver and the server is weblogic5.1 .I have used prepared statement the problem comes in the
    preparedStatement.executeQuery().
    The sql Query is simple query and runs well in all cases and fails only when the long datatype column is included in the query.
    The exception that comes on the weblogic server is that :
    AN UNEXPECTED EXCEPTION DETECTED IN THE NATIVE CODE OUTSIDE THE VM.

    Did you try changing the driver then?
    Please use Oracle's thin driver instead of the oci driver.
    There are many advantages of using the type 4 driver. the first and foremost being that it does not require oracle client side software on your machine. Therefore no enteries to be made in tnsnames.ora
    The thin driver is available in a jar called classes112.zip the class which implements the thin driver is oracle.jdbc.driver.OracleDriver
    the connection string is
    jdbc:oracle:thin:@<machine name>:1521:<sid>
    please try out with the thin driver and let me know.
    regards,
    Abhishek.

  • Problem with SQL query region source containing OLAP clauses

    Hi team,
    I believe I found a bug when HTMLDB validates the SQL Query in a report region.
    My query includes an ORDER BY clause within a windowing function and HTMLDB refuses to accept the source owing to the presence of the ORDER BY and the column heading sort preference.
    Clearly the order-by in a window function has little to do with the column heading sort, but this error prevents me from updating the conditional display item in the page definition.
    Note also that the page was imported smoothly from the 1.5 version, so probably the region source is not checked at that time, but only when you update it "manually".
    So, in the end, if I don't change anything the page works because the sql query is assumed to be correct but unfortunately I need to change the condition and I cannot.
    The problem shows up in page 126 of app 21670, SQL query region.
    Bye,
    Flavio
    PS: may be I can work around this by using the pl/sql function returning the sql query.

    Flavio,
    We're aware of this problem. For now, your workaround is described in this thread:
    HTMLDB 1.6 and "order by" in analytic functions
    Sergio

Maybe you are looking for

  • Eventing in Visual Composer 7.1 Enhancement Package 1

    We are running Enhancment Package 1 on 7.1 and the release note says that client side event is supported.  However I build 2 iViews one with Data Entry text iput and and a signal out and the the sencond one with a signal in and a text field.  I canno

  • Mac Mini with Major Problems

    I'll try to make this short, but it is a looonngg problem. About one month ago my Mac Mini began having problems when I boot up.  The computer would freeze on the opening page where I put in my password.  My wireless keyboard and trackpad would not w

  • Airplay/Mirroring for video on VLC Player

    I am expecting my mid-2013 27" iMac in the mail shortly but my question is can I watch VLC player via airplay/display mirroring on my TV?  I will be running the latest version of Yosemite. Is this possible with the Apple TV (sound included), or is th

  • Trying to disable mouse4/mouse5 IN Firefox, Google-Fu didn't help me out.

    Hi, I'm using my mouse4 and mouse5 buttons for voicechat programs so i've been looking for a way to disable those buttons in Firefox or disable their functionality. I've been searching on the internet and checked out the About:config file but havent

  • How to view by show and not Seasons

    This is probably more an itunes questions but since apple tv users use itunes I thought I'd try here. Is there a way to organize the library so that when you are in TV shows you view just the shows. Say I have lost and theres 4 seasons of it. Can't I