Sql query to display this result

AccountNo
Name
Total Credit
Total Debit
Balance
100010
NEEM
5000
4000
1000
100011
Kamran
50000
49000
1000
100012
Asim
3000
2000
1000

Please follow basic Netiquette and post the DDL we need to answer this. Do you know how to follow industry and ANSI/ISO standards. You should follow ISO-11179 rules for naming data elements. You should follow ISO-8601 rules for displaying temporal data.
Avoid dialect in favor of ANSI/ISO Standard SQL. We need to know the data types, keys and constraints on the table. 
Why did you think anyone could do anything with what you posted???  
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL

Similar Messages

  • How to write sql query that display comma suppurated result using Group by

    Hi,
    I am having data like bellow ,
    Above result got from joining two tables VMTAGroupClient,VMTAipNames .
    Query i have written to display above result is,
    select vgc.VMTAGroupId,vn.VMTAName from VMTAGroupClient vgc inner join VMTAipNames vn
    on vgc.VMTAID=vn.VMTANameID group by vgc.VMTAGroupId,vn.VMTAName 
    using the VMTAGroupId column how to write query to display result result like,
    VMTAGroupID    VMTAs
       1                       VMTA1,VMTA3
       2                       VMTA2,VMTA4,VMTA5
    Regards,
    Anwar Shaik

    Satheesh,
    Here in my case data need to read from two tables VMTAGroupClient, VMTAipNames.
    VMTAGroupId is in one table and VMTAName column in some other table.Iin both the tables VMTAID is common.
    Please check the above result displayed data from two tables.
    can we write same query using join?
    Anwar Shaik

  • SQL query conditional display

    hi
    i create sql report region based on simple sql query like this :
    select count(*) from table;
    what i want is :to display this region if the the count number return by sql is > 0. and dont display if the result null or zero.
    i try options in the conditional display but i faield
    any help to do that will be appreciated
    thank you

    Hi,
    Set region condition type to "Exists (SQL query returns at least one row)" and then place below select to Expression 1
    select 1 from table;Br,Jari

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

  • Need SQL query to get the result.

    Region
    Month
    Trx Type
    Resolution Summary
    AMERICAS
    May-13
    Adjustments
    Correct
    EMEA
    May-13
    Adjustments
    Incorrect
    AMERICAS
    May-13
    Credit Memo
    Incorrect
    EMEA
    May-13
    Invoice
    Correct
    AMERICAS
    May-13
    Credit Memo
    Correct
    OFD
    May-13
    Adjustments
    Correct
    AMERICAS
    May-13
    Invoice
    Incorrect
    LAD
    May-13
    Adjustments
    Correct
    LAD
    May-13
    Adjustments
    Correct
    OFD
    May-13
    Adjustments
    Correct
    Above is my Table and find below the required result.Similarly for other regions as well. Can anyone help me with the SQL Query?
    Region
    Resolution Summary
    Adjustment
    Credit Memo
    Invoice
    Grand Total
    AMERICAS
    Correct
    1
    1
    2
    Incorrect
    0
    1
    1
    2

    Like this?
    SQL> select * from transaction_audit;
    REGION   MTH    TRX_TYPE    RESOLUTIO
    AMERICAS may-13 ADJUSTMENTS CORRECT
    EMEA     may-13 ADJUSTMENTS INCORRECT
    AMERICAS may-13 CREDIT MEMO INCORRECT
    EMEA     may-13 INVOICE     CORRECT
    AMERICAS may-13 CREDIT MEMO CORRECT
    OFD      may-13 ADJUSTMENTS CORRECT
    AMERICAS may-13 INVOICE     INCORRECT
    LAD      may-13 ADJUSTMENTS CORRECT
    LAD      may-13 ADJUSTMENTS CORRECT
    OFD      may-13 ADJUSTMENTS CORRECT
    10 rows selected.
    SQL> select region
      2       , resolution_summary
      3       , count(decode(trx_type, 'ADJUSTMENTS', trx_type)) adjustments
      4       , count(decode(trx_type, 'CREDIT MEMO', trx_type)) credit_memo
      5       , count(decode(trx_type, 'INVOICE'    , trx_type)) invoice
      6    from transaction_audit
      7   group
      8      by region
      9       , resolution_summary
    10   order
    11      by region
    12       , resolution_summary
    13  /
    REGION   RESOLUTIO ADJUSTMENTS CREDIT_MEMO    INVOICE
    AMERICAS CORRECT             1           1          0
    AMERICAS INCORRECT           0           1          1
    EMEA     CORRECT             0           0          1
    EMEA     INCORRECT           1           0          0
    LAD      CORRECT             2           0          0
    OFD      CORRECT             2           0          0
    6 rows selected.
    SQL>

  • SQL*plus not displaying the result of XMLELEMENT

    HI,
    I am using SQL*Plus: Release 10.1.0.4.2
    Connected to: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0
    When I run the following query in SQL*PLUS, I get nothing displayed. However when I run the same query connecting to the same database using SQL Developer then I get the result
    SQL> select XMLELEMENT("form_id",form_id)
    2 FROM collections;
    XMLELEMENT("FORM_ID",FORM_ID)
    In SQL developer
    <form_id>101</form_id>
    I set long and longchuncksize to 32K , and I change linesize, pages, but nothing helped
    Is there any configuration that I have to do, so that SQL*plus display the result of “ select XMLELEMENT("form_id",form_id) query.
    Appreciate you help, thanks

    From a fresh start ;) :
    SQL*Plus: Release 10.1.0.4.2 - Production on Fri Feb 26 15:29:04 2010
    Copyright (c) 1982, 2005, Oracle.  All rights reserved.
    Connected to:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> select xmlelement("value", a.object_name )
      2  from   all_objects a
      3  where  rownum <= 5;
    XMLELEMENT("VALUE",A.OBJECT_NAME)
    SQL> select xmlelement("value", (select b.object_name
      2                              from   all_objects b
      3                              where b.object_name = a.object_name
      4                              )
      5                   )
      6  from   all_objects a
      7  where  rownum <= 5;
    XMLELEMENT("VALUE",(SELECTB.OBJECT_NAMEFROMALL_OBJECTSBWHEREB.OBJECT_NAME=A.OBJE
    <value>ICOL$</value>
    <value>I_USER1</value>
    <value>CON$</value>
    <value>UNDO$</value>
    <value>C_COBJ#</value>
    SQL> show all
    appinfo is OFF and set to "SQL*Plus"
    arraysize 15
    autocommit OFF
    autoprint OFF
    autorecovery OFF
    autotrace OFF
    blockterminator "." (hex 2e)
    btitle OFF and is the first few characters of the next SELECT statement
    cmdsep OFF
    colsep " "
    compatibility version NATIVE
    concat "." (hex 2e)
    copycommit 0
    COPYTYPECHECK is ON
    define "&" (hex 26)
    describe DEPTH 1 LINENUM OFF INDENT ON
    echo OFF
    editfile "afiedt.buf"
    embedded OFF
    escape OFF
    FEEDBACK ON for 6 or more rows
    flagger OFF
    flush ON
    heading ON
    headsep "|" (hex 7c)
    instance "local"
    linesize 80
    lno 9
    loboffset 1
    logsource ""
    long 80
    longchunksize 80
    markup HTML OFF HEAD "<style type='text/css'> body {font:10pt Arial,Helvetica,sans-serif; color:blac
    newpage 1
    null ""
    numformat ""
    numwidth 10
    pagesize 14
    PAUSE is OFF
    pno 1
    recsep WRAP
    recsepchar " " (hex 20)
    release 1002000300
    repfooter OFF and is NULL
    repheader OFF and is NULL
    serveroutput OFF
    shiftinout INVISIBLE
    showmode OFF
    spool OFF
    sqlblanklines OFF
    sqlcase MIXED
    sqlcode 0
    sqlcontinue "> "
    sqlnumber ON
    sqlpluscompatibility 10.1.0
    sqlprefix "#" (hex 23)
    sqlprompt "SQL> "
    sqlterminator ";" (hex 3b)
    suffix "sql"
    tab ON
    termout ON
    timing OFF
    trimout ON
    trimspool OFF
    ttitle OFF and is the first few characters of the next SELECT statement
    underline "-" (hex 2d)
    USER is "HR"
    verify ON
    wrap : lines will be wrapped
    SQL>
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Sql query and speed of result

    public List Get(String pid, String str, List ls) {
              List a = new Vector();
              List d = new Vector();
              pcl.addAll("num"));-----list contains numbers which are present in this column "num"
              ListIterator pc = d.listIterator();
              while (pc.hasNext()) {
                   String dt = (String) pc.next();
                   List world = new Vector();
                   world
                             .addAll(ABG());.............tThis method will extratct each row one at a time and i think this while is creating problem as it is taking one row at time.process it and again go to database.I am getting result in 10 minute .is there anyway to reduce this time.Number of rows in table 1000

    rashmi_007 wrote:
    1)ABG() method contains this statement
    stmt = con.createStatement();
                   rs = stmt.executeQuery("select " + ruuyuyuy
                             + " from tablename where ID='" + id + "' "); this result we get in original code one by one each rowTotally wrong. Network latency is killing you. It's the classic noob error.
    Learn how to write JOINs.
    2)1) Slow DB server.-mysql 5No
    2) Slow DB connection.-not sureNo
    3) RAM memory shortage.-1GBMore than enough.
    4) Poor indexed table.-NOT usedWrong. Your table should at least have a primary key.
    5) Poor SQL query.-is written aboveTotally wrong.
    6) Poor code logic.-that is the reson I also think.As every time adg method get a row and then process it ,then again it goes to fetch new row by calling adg.
    so what could be done to improve speed .thanksLearn how SQL works and write a JOIN.
    %

  • Sql query - number display

    hi all,
    Can anyone let me know how to display the number in the following manner thru sql query.
       Actual value is 20      Then the  output to be :  00002000
       if the value is   20.34  Then the output to be  :  000020.34 Thanks in advance.

    CCYYMMDDThere is. Give the centure, year, month and day.
    SQL> select to_char(sysdate,'CCYYMMDD') from dual;
    TO_CHAR(
    21070128
    if so wht the use of it.Just like it, I don't know, since it may have confusing against the year 2107...
    But maybe like this will be more properly :
    SQL> select to_char(sysdate,'CCth, YYYYMMDD') from dual
    SQL> /
    TO_CHAR(SYSDAT
    21ST, 20070128
    SQL> Nicolas.

  • Sql query to generate this output

    Hi,
    I have a table as follows;
    SET_MASTER
    ID set_id attribute_id attribute_value
    1 1 2 10
    2 1 3 20
    3 1 4 50
    4 1 5 60
    5 2 2 10
    6 2 3 30
    7 2 4 40
    8 2 5 50
    I want to generate an output as folllows;
    Attr_id Set1_attr_value Set2_attr_value min_attr_value max_attr_value
    2 10 10 10 10
    3 20 30 20 30
    4 50 40 40 50
    5 60 50 50 60
    Please provide the query to generate this output.
    Thanks.

    SQL> create table set_master (id,set_id,attribute_id,attribute_value)
      2  as
      3  select 1, 1, 2, 10 from dual union all
      4  select 2, 1, 3, 20 from dual union all
      5  select 3, 1, 4, 50 from dual union all
      6  select 4, 1, 5, 60 from dual union all
      7  select 5, 2, 2, 10 from dual union all
      8  select 6, 2, 3, 30 from dual union all
      9  select 7, 2, 4, 40 from dual union all
    10  select 8, 2, 5, 50 from dual
    11  /
    Tabel is aangemaakt.
    SQL> select attribute_id attr_id
      2       , max(decode(set_id,1,attribute_value)) set1_attr_value
      3       , max(decode(set_id,2,attribute_value)) set2_attr_value
      4       , least(max(decode(set_id,1,attribute_value)),max(decode(set_id,2,attribute_value))) min_attr_value
      5       , greatest(max(decode(set_id,1,attribute_value)),max(decode(set_id,2,attribute_value))) max_attr_value
      6    from set_master
      7   group by attribute_id
      8   order by attribute_id
      9  /
       ATTR_ID SET1_ATTR_VALUE SET2_ATTR_VALUE MIN_ATTR_VALUE MAX_ATTR_VALUE
             2              10              10             10             10
             3              20              30             20             30
             4              50              40             40             50
             5              60              50             50             60
    4 rijen zijn geselecteerd.Regards,
    Rob.

  • HOW TO CHANGE SQL QUERY TO GET SPECIFIC RESULT

    I HAVE FOLLOWING QUERY AND ITS FUNCTIONING BUT I WANT ALL THOSE RECORD SHOULD BE DISPLADE WICH HAVE NO TRANSACTION IN SALES ANS SALES RETURN WHILE RETREVING DATA FROM DATABASE.
    I TRIED TO USE + OPERATOR BUT I DON'T KNOW HOW TO CHANGE THE QUERY TO GET THE RESULT
    MAIN TABLE IS BEING USED TO FETCH RECORD
    SALES_HEADER,SALES_DETAIL
    SALES_HEADERR,SALES_DETAILR
    STOCK_REG
    AND THE QUERY IS
    select s.item_code,S.DESCR,s.GRAND_TOTAL,
    sum(decode(d.dayno,01,NVL(S.QTY,0),0)) DAY1,
    sum(decode(d.dayno,02,NVL(S.QTY,0),0)) DAY2,
    sum(decode(d.dayno,03,NVL(S.QTY,0),0)) DAY3,
    sum(decode(d.dayno,04,NVL(S.QTY,0),0)) DAY4,
    sum(decode(d.dayno,05,NVL(S.QTY,0),0)) DAY5,
    sum(decode(d.dayno,06,NVL(S.QTY,0),0)) DAY6,
    sum(decode(d.dayno,07,NVL(S.QTY,0),0)) DAY7,
    sum(decode(d.dayno,08,NVL(S.QTY,0),0)) DAY8,
    sum(decode(d.dayno,09,NVL(S.QTY,0),0)) DAY9,
    sum(decode(d.dayno,10,NVL(S.QTY,0),0)) DAY10,
    sum(decode(d.dayno,11,NVL(S.QTY,0),0)) DAY11,
    sum(decode(d.dayno,12,NVL(S.QTY,0),0)) DAY12,
    sum(decode(d.dayno,13,NVL(S.QTY,0),0)) DAY13,
    sum(decode(d.dayno,14,NVL(S.QTY,0),0)) DAY14,
    sum(decode(d.dayno,15,NVL(S.QTY,0),0)) DAY15,
    sum(decode(d.dayno,16,NVL(S.QTY,0),0)) DAY16,
    sum(decode(d.dayno,17,NVL(S.QTY,0),0)) DAY17,
    sum(decode(d.dayno,18,NVL(S.QTY,0),0)) DAY18,
    sum(decode(d.dayno,19,NVL(S.QTY,0),0)) DAY19,
    sum(decode(d.dayno,20,NVL(S.QTY,0),0)) DAY20,
    sum(decode(d.dayno,21,NVL(S.QTY,0),0)) DAY21,
    sum(decode(d.dayno,22,NVL(S.QTY,0),0)) DAY22,
    sum(decode(d.dayno,23,NVL(S.QTY,0),0)) DAY23,
    sum(decode(d.dayno,24,NVL(S.QTY,0),0)) DAY24,
    sum(decode(d.dayno,25,NVL(S.QTY,0),0)) DAY25,
    sum(decode(d.dayno,26,NVL(S.QTY,0),0)) DAY26,
    sum(decode(d.dayno,27,NVL(S.QTY,0),0)) DAY27,
    sum(decode(d.dayno,28,NVL(S.QTY,0),0)) DAY28,
    sum(decode(d.dayno,29,NVL(S.QTY,0),0)) DAY29,
    sum(decode(d.dayno,30,NVL(S.QTY,0),0)) DAY30,
    sum(decode(d.dayno,31,NVL(S.QTY,0),0)) DAY31,
    sum(S.qty) TU
    FROM
    (select nvl(sales_detail.qty+sales_detail.bonus,0) as qty,
    sales_detail.item_code AS ITEM_CODE,
    stock_reg.descr AS descr,
    s_date as sale_date,stock_reg.GRAND_TOTAL AS GRAND_TOTAL FROM
    SALES_DETAIL,SALES_HEADER,STOCK_REG
    WHERE SALES_DETAIL.S_ID = SALES_HEADER.S_ID AND
    SALES_DETAIL.ITEM_CODE = STOCK_REG.ITEM_CODE(+) AND
    STOCK_REG.COMCODE='C1'
    UNION all
    select -1*nvl(sales_detailR.qty+sales_detailR.bonus,0) as qty,
    sales_detailR.item_code AS ITEM_CODE,
    stock_reg.descr AS descr,
    RETURN_date as sale_date,stock_reg.GRAND_TOTAL AS GRAND_TOTAL FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.ITEM_CODE = STOCK_REG.ITEM_CODE(+) AND
    STOCK_REG.COMCODE='C1') S,
    (select level as dayno
    from dual
    connect by level <= 31) d
    where d.dayno = to_char(s.sALE_date, 'DD') AND TO_DATE(S.SALE_DATE) BETWEEN '&FROMDATE' AND '&TODATE'
    GROUP BY S.ITEM_CODE,S.DESCR,S.GRAND_TOTAL

    well my query running successfully just the quesion was that i wanted to bring some changes in the query to retrieve the complete record which has no transaction in sales
    for exmple
    if i write the quey
    select dept.deptno,sum(sal) from emp,dept
    where dept.deptno = emp.deptno
    group by dept.deptno
    the recult comes as
    DEPTNO SUM(SAL)
    10 8750
    20 10875
    30 9400
    though there is another deptno which is deptno no 40
    have no sal
    and when i use this query
    select dept.deptno,sum(sal) from emp,dept
    where dept.deptno = emp.deptno(+)
    group by dept.deptno
    it shows the dept no 40 also
    DEPTNO SUM(SAL)
    10 8750
    20 10875
    30 9400
    40
    so to get this i posted query which was to long to understand easily.
    i accept that i sholud post short query to make other understand
    so check out this
    select STOCK_rEG.item_code AS ITEM_CODE,SUM(qty) as qty
    FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.STOCKCODE = STOCK_REG.STOCKCODE
    AND RETURN_DATE = '01-APR-08'
    GROUP BY STOCK_rEG.item_code
    ORDER BY TO_NUMBER(ITEM_CODE) ASC
    when i execute this query i get the following result
    ITEM_CODE QTY
    84 2
    102 3
    108 3
    116 6
    166 3
    170 3
    thoug there is other items are aalso available in stock which transaction
    yet not been done or not been sold out/
    so when i use the outer join i get the same result
    select STOCK_rEG.item_code AS ITEM_CODE,SUM(qty) as qty
    FROM
    SALES_DETAILR,SALES_HEADERR,STOCK_REG
    WHERE SALES_DETAILR.SR_ID = SALES_HEADERR.SR_ID AND
    SALES_DETAILR.STOCKCODE(+) = STOCK_REG.STOCKCODE
    AND RETURN_DATE = '01-APR-08'
    GROUP BY STOCK_rEG.item_code
    ORDER BY TO_NUMBER(ITEM_CODE) ASC
    ITEM_CODE QTY
    84 2
    102 3
    108 3
    116 6
    166 3
    170 3
    hope i tried to make u understand on better way

  • Passing Parameters to SQL Query and Displaying Result

    The user enters a serial number in a text box and then pushes a button to get info about the serial number. I do this with two regions. The first region has the text box and the button. The second region is a Report type region and contains the following SQL:
    select case
    when "WARRANTYSTATUS"."OUTOFWARRANTYDATE" >= sysdate then
    'Serial Number '||"WARRANTYSTATUS"."SERIALNUMBER"||' is in warranty.'
    else
    'Serial Number '||"WARRANTYSTATUS"."SERIALNUMBER"||' is out of warranty.'
    end as "The result is:"
    from "WARRANTYSTATUS"
    where "WARRANTYSTATUS"."SERIALNUMBER" in (:P1_SERIALNUMBER)
    For a single serial number of the form CU5-0799 every thing works. I am a little suprised this works because the SERIALNUMBER in the WARRANTYSTATUS table is of type varchar2 which means the serial number in the where clause must be surrounded by single quoties. Not sure where the single quoties are being added.
    However, what I like to do is to enter more that one serial number, seperated by commas, in the same text box, and then the query return a result for each serial number. What I would like to enter is:
    CU5-0799, CU5-07132, CU5-89345
    The problem is this string of three serial numbers will needs to be have single quotes around each serial number at the level of the sql statement. So the question is how do I make this work?? Thanks for the help in advance.

    Bob,
    If you would change your OTN handle to something more mnemonically friendly, that would help us. Thanks.
    This topic is addressed fully, with various techniques described, here: Re: Search on a typed in list of values .
    I am a little suprised this works because the SERIALNUMBER in the WARRANTYSTATUS table is of type varchar2 which means the serial number in the where clause must be surrounded by single quoties.
    Not true. Quotes are used for literals, not bind variables.
    Scott

  • XML SQL query not displaying result in SQLPLUS

    Have a registered schema and 1 xml document successfully inserted using Oracle 10.2.0.3.0
    I then run the following query:
    select extract(object_value,'/warehouse/warehousename')from xwarehouses;
    Expecting 1 record to be returned in SQLPLUS but get the following result:
    EXTRACT(OBJECT_VALUE,'/WAREHOUSE/WAREHOUSENAME')
    1 row selected.
    Can anyone shed any light? Is it a setting in SQLPlus

    Thanks A Non
    I still cannot see where I am going wrong!
    The schema registers okay. My inserts work fine.
    --register the schema
    begin
    dbms_xmlschema.registerSchema(
    'http://www.oracle.com/xwarehouses.xsd',
    '<schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.oracle.com/xwarehouses.xsd"
    xmlns:who="http://www.oracle.com/xwarehouses.xsd"
    version="1.0"
    elementFormDefault="unqualified">
    <simpleType name="RentalType">
    <restriction base="string">
    <enumeration value="Rented"/>
    <enumeration value="Owned"/>
    </restriction>
    </simpleType>
    <simpleType name="ParkingType">
    <restriction base="string">
    <enumeration value="Street"/>
    <enumeration value="Lot"/>
    </restriction>
    </simpleType>
    <element name = "Warehouse">
    <complexType>
    <sequence>
    <element name = "WarehouseId" type = "positiveInteger"/>
    <element name = "WarehouseName" type = "string"/>
    <element name = "Building" type = "who:RentalType"/>
    <element name = "Area" type = "positiveInteger"/>
    <element name = "Docks" type = "positiveInteger"/>
    <element name = "DockType" type = "string"/>
    <element name = "WaterAccess" type = "boolean"/>
    <element name = "RailAccess" type = "boolean"/>
    <element name = "Parking" type = "who:ParkingType"/>
    <element name = "VClearance" type = "positiveInteger"/>
    </sequence>
    </complexType>
    </element>
    </schema>',
    TRUE, TRUE, FALSE, FALSE);
    end;
    --create the table
    CREATE TABLE xwarehouses OF XMLTYPE
    XMLSCHEMA "http://www.oracle.com/xwarehouses.xsd"
    ELEMENT "Warehouse";
    --Insert
    INSERT INTO xwarehouses VALUES(
    xmltype.createxml('<?xml version="1.0"?>
    <who:Warehouse xmlns:who="http://www.oracle.com/xwarehouses.xsd"
    xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
    xs:schemaLocation="http://www.oracle.com/xwarehouses.xsd
    http://www.oracle.com/xwarehouses.xsd">
    <WarehouseId>1</WarehouseId>
    <WarehouseName>Southlake, Texas</WarehouseName>
    <Building>Owned</Building>
    <Area>25000</Area>
    <Docks>2</Docks>
    <DockType>Rear load</DockType>
    <WaterAccess>true</WaterAccess>
    <RailAccess>false</RailAccess>
    <Parking>Street</Parking>
    <VClearance>10</VClearance>
    </who:Warehouse>'));
    I don't know if you see the error
    Thanks again.

  • How to write a query to get this result?

    I have four tables. how to get the result meet the following condition?
    1,select all from USERACC_FOR_DOM_REP table.
    2,then take out(filter out) the username from EXCEPTION_ACC table where EXCEPTION_ACC.username=USERACC_FOR_DOM_REP.username and
    EXCEPTION_ACC.TARGET_DB=USERACC_FOR_DOM_REP.TARGET_DB
    3, then take out(filter out) the username from MAX_USER_LOGIN table where MAX_USER_LOGIN.username=USERACC_FOR_DOM_REP.username and
    MAX_USER_LOGIN.TARGET_DB=USERACC_FOR_DOM_REP.TARGET_DB and MAX_USER_LOGIN.LAST_LOGIN < sysdate -90).
    4, then take out(filter out) the username from MYTABLE table where MYTABLE.username=USERACC_FOR_DOM_REP.username and
    MYTABLE.TARGET_DB=USERACC_FOR_DOM_REP.TARGET_DB
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    SQL> desc USERACC_FOR_DOM_REP
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    ACCOUNT_STATUS NOT NULL VARCHAR2(32)
    TARGET_DB VARCHAR2(9)
    SQL> desc EXCEPTION_ACC
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    TARGET_DB VARCHAR2(15)
    SQL> desc MAX_USER_LOGIN
    Name Null? Type
    USERNAME NOT NULL VARCHAR2(30)
    TARGET_DB VARCHAR2(9)
    LAST_LOGIN DATE
    INSERT_DATE DATE
    SQL> desc MYTABLE
    Name Null? Type
    USERNAME VARCHAR2(20)
    TARGET_DB VARCHAR2(20)

    sorry if i didn't make this clear.
    here is the problem. i have three tables. like below. i also give some sample data
    USERS, USER_MAX_LOGIN, EXCEPTION_USER
    USERS table has all the user information for each user in each database.
    USER_MAX_LOGIN has those users who logged in within 1 year (we keep 1 year audit data)
    EXCEPTION_USER has user which should be excluded from the report.
    My report need to find all users in all databases who has not logged in for more than 90 days.
    USERS
    username     target_db     profile     
    u1     d1     user     
    u2     d1     user     
    u3     d2     user     
    u1     d2     user     
    u2     d2     user     
    u3     d1     user     
    USER_MAX_LOGIN
    username     target_db     last_login_date     
    u1     d1     02-Jan-12     
    u3     d2     06-Aug-11     
    u1     d2     06-Aug-11     
    u2     d2     06-Sep-11     
    EXCEPTION_USER
    username     target_db          
    u2     d1          
    THIS IS THE REPORT I NEED TO BE LOOK LIKE.               
    username     target_db     last_login     profile
    u3     d2     06-Aug-11     user
    u1     d2     06-Aug-11     user
    u2     d2     06-Sep-11     user
    u3     d1     UNKNOWN     user <<----- the unknown means we don't know when the user logged in last time. the user_max_login table does not have its information.

  • XML sql query not displayed using SQLPLUS

    Have a registered schema and 1 xml document successfully inserted using Oracle 10.2.0.3.0
    I then run the following query:
    select extract(object_value,'/warehouse/warehousename')from xwarehouses;
    Expecting 1 record to be returned in SQLPLUS but get the following result:
    EXTRACT(OBJECT_VALUE,'/WAREHOUSE/WAREHOUSENAME')
    1 row selected.
    Can anyone shed any light?

    Thanks A-non.
    I checked the long and longchunksize settings and they are the same as yours.
    Your sample code runs perfectly but still my original problem remains.

  • Sql query to achieve this

    Hi all,
    Query to achieve the below output:
    source table :
    empno,_deptno_
    110,10
    110,20
    110,30
    120,10
    130,20
    130,30
    130,30
    110,40
    I need the output in below format:
    empno,deptno
    110,10$20$30$40
    120,10
    130,20$30$30

    or:
    SQL> -- generating sample data:
    SQL> with t as (
      2  select 110 empno,10 deptno from dual union
      3  select 110,20 from dual union
      4  select 110,30 from dual union
      5  select 120,10 from dual union
      6  select 130,20 from dual union
      7  select 130,30 from dual union
      8  select 130,30 from dual union
      9  select 110,40 from dual
    10  )
    11  --
    12  -- actual query:
    13  --
    14  select empno
    15  ,      replace(sys_connect_by_path(deptno, ','),',') deptno
    16  from ( select empno
    17         ,      deptno
    18         ,      row_number() over (partition by empno order by deptno) rn
    19         from    t
    20       )
    21  where connect_by_isleaf=1    
    22  start with rn=1
    23  connect by empno=prior empno
    24         and rn = prior rn+1;
         EMPNO DEPTNO
           110 10203040
           120 10
           130 2030
    3 rows selected.

Maybe you are looking for

  • JSP, BC4J, Row Tag: what is the best way to delete multiple rows?

    Hi all. I have a JSP Edit page with three datasources on it. The tables these VO's represent (A, B and C) have a Parent --> Child (1:1 between A and B) relationship and then another Parent --> Child (1:n between B and C) relationship. So the user ret

  • Red/blue flash on my screen?

    I see this red, blue strip/flash thing on my screen every night. Is my laptop broken? when I restart it, it goes away but it comes back at night. I'm scared that it might shut down or something. I haven't spilled anything over it and take good care o

  • SQLDeveloper can't generate an explain-plan when using "cube"

    If I want to create an explain-plan from the following statement, I get no explain-plan: SELECT 1 FROM   dual GROUP BY CUBE( 2, 2, 2, 2, 2, 2, 2, 2, 2 )If I now want to create an explain-plan again, I get the following message (and still no explain-p

  • Behavior very strange

    I make a query of the Customer Table with Left Join to other two tables and when I put c.DocumentNumber like '1%' ó c.DocumentNumber like '112%' the query returns rows in one second and when I put c.DocumentNumber like '11%' the query returns rows in

  • Where Should the JavaScript Go if I'm Calling from the Page HTML Header?

    In the Application Express User's Guide under "Calling the JavaScript File from the HTML Header Attribute" point 4 says:In HTML Header, call the JavaScript file using the following syntax: <script src="/my_images/custom.js" type="text/javascript"></s