Grouping result set by a column in a query without aggregate function

In the below result set, several columns appear for one table.
col data_Type format a12
col column_name format a10
set lines 100
set pages 50
SELECT table_name, column_name FROM user_tab_cols WHERE char_used = 'B'
AND TABLE_name NOT LIKE 'BIN%' ORDER BY TABLE_NAME;
TABLE_NAME                     COLUMN_NAM
BONUS                          JOB
BONUS                          ENAME
DEPT                           DNAME
DEPT                           LOC
EMP                            JOB
EMP                            ENAME
EMP_DTL                        ENAME
EMP_DTL                        LOC
EMP_DTL                        CONVN_LOC
MEMBER                         GENDER
MEMBER                         TEAM
MEMBER                         MEMBERTYPE
MEMBER                         FIRSTNAME
MEMBER                         LASTNAME
MEMBER                         PHONE
ORDERS                         STATUS
SYS_CONFIG                     CODE_ID
SYS_CONFIG                     FLAG_A
TOURNAMENT                     TOURTYPE
TOURNAMENT                     TOURNAMEI don't want the table_name to repeat for every columns within a table_name group. If i use SQLPLUS's BREAK command, it would
suppress duplicates
break on table_nameand the resultset would look like
TABLE_NAME                     COLUMN_NAM
BONUS                          JOB
                               ENAME
DEPT                           DNAME
                               LOC
EMP                            JOB
                               ENAME
EMP_DTL                        ENAME
                               LOC
                               CONVN_LOC
MEMBER                         GENDER
                               TEAM
                               MEMBERTYPE
                               FIRSTNAME
                               LASTNAME
                               PHONE
ORDERS                         STATUS
SYS_CONFIG                     CODE_ID
                               FLAG_A
TOURNAMENT                     TOURTYPE
                               TOURNAME
TYPE                           TYPE
X                              ENAME
Y                              ENAMEBut how can i do this using oracle SQL?

Analytics?
SQL> with t as
  2  (
  3  select 'A' col1, 100 col2 from dual
  4  union all
  5  select 'A' col1, 200 col2 from dual
  6  union all
  7  select 'B' col1, 800 col2 from dual
  8  union all
  9  select 'B' col1, 400 col2 from dual
10  union all
11  select 'C' col1, 500 col2 from dual
12  )
13  select decode(row_number() over (partition by col1 order by col2), 1, col1, null) col1
14         ,col2
15  from t
16  /
C      COL2
A    100.00
     200.00
B    400.00
     800.00
C    500.00
SQL>Cheers
Sarma.

Similar Messages

  • How to group result set to count values in several (2) attributes?

    Hi there,
    the (simplified) query at the bottom returns the following result set:
    OBJ_ID Attr 1 Attr2
    22674886 HAK44221 GEB132542
    22674886 HAK44221 GEB92751
    22674886     HAK44222 GEB92744
    22674886     HAK17113 null
    However, we need the number of different Attr 1 and Attr2 counted, which should result in the this:
    OBJ_ID Attr 1 Attr2
    22674886 3 3
    We trried using "group by grouping sets", "group by" and also took a glance at "cube" but didn't manage to get the desired result, mainly due to the fact, that Attr2 may contain null values.
    We managed to find a solution using a GTT or a view. Can anybody give a hint how to solve that without using temporary tables?
    Best regards
    Pat
    SELECT
    o.obj_id,
    o2.obj_name as Attr1,
    g.ckw_nis_nummer as Attr2
    FROM objekte o
    JOIN eigenschaftsdaten d0
    ON (o.obj_id = d0.obj_id AND d0.eig_id = 2525755)
    LEFT JOIN eigenschaftsdaten d8
    ON (d0.egd_wert=substr(d8.egd_wert,1,instr(d8.egd_wert, ' ')-1) and d8.eig_id=2525976)
    LEFT JOIN objekte o2
    ON o2.obj_id=d8.obj_id
    LEFT join gebaeude g
    ON o2.obj_id=g.parent_house_service

    Hi,
    That looks like COUNT (DISTINCT ...):
    SELECT       o.obj_id
    ,       COUNT (DISTINCT o.obj_name)          AS attr1
    ,       COUNT (DISTINCT g.ckw_nis_nummer)     AS attr2
    FROM        objekte o
    JOIN        eigenschaftsdaten     d0     ON   o.obj_id      = d0.obj_id
                               AND  d0.eig_id       = 2525755
    LEFT JOIN eigenschaftsdaten      d8     ON   d0.egd_wert = SUBSTR ( d8.egd_wert
                                                             , 1
                                              , INSTR (d8.egd_wert, ' ') - 1
                             and d8.eig_id=2525976)
    LEFT JOIN objekte          o2     ON  o2.obj_id      = d8.obj_id
    LEFT JOIN gebaeude           g     ON  o2.obj_id      = g.parent_house_service
    Depending on your data and your requirements, you may need to join some of the tables separatemly, do a GROUP BY to get attr2, and then join those results to the other tables.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data. WSimplify the problem as much as possible. For exam[ple, if your real problem involves 5 tables, but the part you don't understand can be shown with only 1 or 2 tables, then post sample data and results for those 1 or 2 tables only.
    Point out where the query above is getting the wrong results, and explain, using specific examples, how you get those results from the sample data in those places.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Is it possible to filter the nested table result set of table column

    Hi
    Create or replace type address_record
    as object
    ( address_no number,
    address_name varchar2,
    address_startDate date,
    address_expiryDate date
    create or replace type address_rec_tab
    as table of address_record;
    Create table employee
    (emp_no number,
    emp_name varchar2,
    adresses address_rec_tab
    1st approach
    ==========
    <pre>
    select
    emp.emp_no,
    emp.emp_name,
    emp.addresses
    from employee emp,
    table(*emp.addresses*) add
    where add.address_expiryDate >=sysdate
    </pre>
    In the above example my SQL query address collection object is not returning filtered or current address list.
    I suppose this is due to fact taht my where clause is not attached to the nested table.
    Through my reading I gather that I can only use the following query to filter the address collection.
    2nd approach
    ==========
    <pre>
    select
    emp.emp_no,
    emp.emp_name
    cursor(select address_no,
    address_name,
    address_startDate,
    address_expiryDate
    from employee emp,
    table (*emp.addresses*) add
    where add.address_expiry_date >=sysdate)
    from employee emp,
    table (*emp.addresses*) add
    where add.address_expiry_date >=sysdate) -- probably this redundent
    </pre>
    But this approch forces me to rebuild addresses collection object.
    I was wondering anybody can suggest me a way so that 1st approach works? I do not have to rebuild collection object in this way.
    Thanks for your help in advance
    Regards
    Charan

    Create statements have been slightly modified;
    Create or replace type address_record as object
    ( address_no          number,
      address_name        varchar2(20),
      address_startDate   date,
      address_expiryDate  date
    create or replace type address_rec_tab as table of address_record;
    Create table employee
    (emp_no number,
    emp_name varchar2(20),
    add_list address_rec_tab
    nested table add_list store as a_list
    insert into employee values (1, 'KMCHARAN', address_rec_tab ( address_record(1, 'NORTH POLE', trunc(sysdate-1), trunc(sysdate+10) ) ,
                                                                  address_record(1, 'SOUTH_POLE', trunc(sysdate-1), trunc(sysdate+10) )
    insert into employee values (2, 'ME', address_rec_tab ( address_record(2, 'EAST', trunc(sysdate-2), trunc(sysdate+12) ) ,
                                                            address_record(2, 'WEST', trunc(sysdate-2), trunc(sysdate+12) )
    SQL> l
      1  select *
      2  from employee
      3      ,table(add_list) a
      4* where a.Address_StartDate = trunc(sysdate-1)
    SQL> /
        EMP_NO EMP_NAME
    ADD_LIST(ADDRESS_NO, ADDRESS_NAME, ADDRESS_STARTDATE, ADDRESS_EXPIRYDATE)
    ADDRESS_NO ADDRESS_NAME         ADDRESS_S ADDRESS_E
             1 KMCHARAN
    ADDRESS_REC_TAB(ADDRESS_RECORD(1, 'NORTH POLE', '08-APR-10', '19-APR-10'), ADDRESS_RECORD(1, 'SOUTH_
             1 NORTH POLE           08-APR-10 19-APR-10
             1 KMCHARAN
    ADDRESS_REC_TAB(ADDRESS_RECORD(1, 'NORTH POLE', '08-APR-10', '19-APR-10'), ADDRESS_RECORD(1, 'SOUTH_
             1 SOUTH_POLE           08-APR-10 19-APR-10

  • Scrollable result set fails with doubles

    Hi there,
    i have a strange behaviour using the 10g thin JDBC driver:
    Using a scrollable result set the driver fails reading a BINARY_DOUBLE value from the result set with rs.getDouble(column) as long as the value is not null. The SQLException reports "Conversion to double failed".
    When i use a forward-only result set instead, the value can be retrieved without any error. Can anyone explain this or give a workaround?
    Thanks in advance,
    Thorsten

    ThorstenS,
    ScrollableResultSet stores BINARY_DOUBLE column as oracle.sql.BINARY_DOUBLE & since, oracle.sql.BINARY_DOUBLE does not have method to convert to double you are seeing this error.
    The workaround would be to do,
    rs.getBINARYDOUBLE(1).stringValue()
    & please file an enhancement request against Jdbc.
    =
    Ashok

  • Grouping results by Month

    Hello,
    I am building a report that is grouping results by Week. So
    far the query will pull the data from the database by week. I have
    a weekstart date and weekending date in the results. This report
    will have Year to date results and I wanted to break the results to
    display by Month. How can I achive this?
    Thanks for the help!

    Hello,
    I am building a report that is grouping results by Week. So
    far the query will pull the data from the database by week. I have
    a weekstart date and weekending date in the results. This report
    will have Year to date results and I wanted to break the results to
    display by Month. How can I achive this?
    Thanks for the help!

  • Help with streaming result sets and prepared statements

    hi all
    I create a callable statement that is capable of streaming.
    statement = myConn2.prepareCall("{call graphProc(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}",java.sql.ResultSet.TYPE_FORWARD_ONLY,
    java.sql.ResultSet.CONCUR_READ_ONLY);
    statementOne.setFetchSize(Integer.MIN_VALUE);
    the class that contains the query is instantiated 6 times the first class streams the results beautifully and then when the second
    rs = DatabaseConnect.statementOne.executeQuery();
    is executed I get the following error
    java.sql.SQLException: Can not use streaming results with multiple result statements
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)
    at com.mysql.jdbc.MysqlIO.readAllResults(MysqlIO.java:1370)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1688)
    at com.mysql.jdbc.Connection.execSQL(Connection.java:3031)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:943)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1049)
    at com.mysql.jdbc.CallableStatement.executeQuery(CallableStatement.java:589)
    the 6 instances are not threaded and the result set is closed before the next query executes is there a solution to this problem it would be greatly appreciated
    thanks a lot
    Brian

    Database resources should have the narrowed scope
    possible. I don't think it's a good idea to use a
    ResultSet in a UI to generate a graph. Load the data
    into an object or data structure inside the method
    that's doing the query and close the ResultSet in a
    finally block. Use the data structure to generate
    the graph.
    It's an example of MVC and layering.
    Ok that is my bad for not elaborating on the finer points sorry, the results are not directly streamed into the graphs from the result set. and are processed in another object and then plotted from there.
    with regards to your statement in the beginning I would like to ask if you think it at least a viable option to create six connections. with that said would you be able to give estimated users using the six connections under full usage.
    just a few thoughts that I want to
    bounce off you if you don't mind. Closing the
    statement would defeat the object of of having a
    callable statement How so? I don't agree with that.
    %again I apologise I assumed that since callable statements inherit from prepared statements that they would have the pre compiled sql statement functionality of prepared statements,well If you consider in the example I'm about to give maybe you will see my point at least with regards to this.
    The statement that I create uses a connection and is created statically at the start of the program, every time I make a call the same statement and thus connection is used, creating a new connection each time takes up time and resources. and as you know every second counts
    thanks for your thoughts
    Brian.

  • Non-scrolling result sets

    In kodo 3 "Kodo now uses non-scrolling result sets by default, and fetches
    all query results up-front by default. See the large result set section of
    the reference guide for how to configure large result set handling if
    needed"
    How does 2.5.3 work? Is there any way to use non-scrolling result sets in
    it? I always use fetch all mode and scrolling result set would be a big
    overhead for me

    Alex-
    If you have "com.solarmetric.kodo.DefaultFetchThreshold" set to -1, then
    Kodo will always use non-scrolling ResultSets (as well as instantiating
    all the results up front).
    http://docs.solarmetric.com/manual.html#com.solarmetric.kodo.DefaultFetchThreshold
    In article <bks8r7$7op$[email protected]>, Alex Roytman wrote:
    In kodo 3 "Kodo now uses non-scrolling result sets by default, and fetches
    all query results up-front by default. See the large result set section of
    the reference guide for how to configure large result set handling if
    needed"
    How does 2.5.3 work? Is there any way to use non-scrolling result sets in
    it? I always use fetch all mode and scrolling result set would be a big
    overhead for me
    Marc Prud'hommeaux [email protected]
    SolarMetric Inc. http://www.solarmetric.com

  • ORA-19036: Invalid query result set in newContextFromHierarchy()

    Hi,
    I'm getting this error occasionally when using a CONNECT BY query to generate a hierarchical XML. Using Oracle 10g. The action suggested is "Make sure the query used in newContextFromHierarchy() is a CONNECT BY query or the query returns the result set have the same property as the result set generated by a CONNECT BY query." Not very helpful since I am using a CONNECT BY query which works fine 99% of the time. Appreciate any help.
    Thanks!

    Strange, never got notified that anyone replied. Oracle version is:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
    With the Partitioning, Real Application Clusters, OLAP, Data Mining
    and Real Application Testing options
    Volume of data is not large.
    DBMS_XMLGEN.NEWCONTEXTFROMHIERARCHY('SELECT plevel,
                    XMLELEMENT("PORTFOLIO",
                               XMLELEMENT("MPFL_ID", MPFL_ID),
                               XMLELEMENT("MPFL_NAME", MPFL_NAME),
                               XMLELEMENT("MPFL_DESC", MPFL_DESC),
                               XMLELEMENT("PFL_ID", PFL_ID),
                               XMLELEMENT("PFL_NAME", PFL_NAME),
                               XMLELEMENT("PFL_DESC", PFL_DESC),
                               XMLELEMENT ("PFTYP_NAME", PFTYP_NAME),
                               XMLELEMENT("HIDE", HIDE),
                               XMLELEMENT("REF_MGR", REF_MGR))
                FROM (WITH TEST_TREE AS..
    Can't share the exact query but it's using a WITH clause which contains a query using a CONNECT BY NOCYCLE. There are several UNION ALLs of the result set generated by the WITH clause.
    Thanks for your help!
    Message was edited by: user12110856

  • Retrieve varchar column from Oracle query in a resulset

    Hi, I'am a begginer in JSP Technologies.
    I've do a small jsp that opens a db connection to an oracle, execute a query a show results.
    When the columns of the query are int I've no problem, the jsp show the columns of the resulset, but when the columns selected are varchars the jsp doesn't show anything....
    Can anyone help me?
    Example:
    Table: CUSTOMERS
    Col1 : ID_COSTUMER int
    Col2: CUSTOMER_NAME varchar
    <%
    Connection canal = null;
    ResultSet tabla = null;
    Statement instruccion=null;
    try { Class.forName("oracle.jdbc.driver.OracleDriver");
    canal=DriverManager.getConnection("jdbc:oracle:thin:@XXXXXXXXXXXXXXXXXXXp");
    instruccion = canal.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
    } catch(java.lang.ClassNotFoundException e){};
    String Query = "SELECT ID_CUSTOMER FROM CUSTOMERS";
    try { tabla = instruccion.executeQuery(Query);
    out.println("<TABLE Border=10 CellPadding=5><TR>");
    out.println("<TD>CUSTOMER</TD></TR>");
    while(tabla.next()) {
    out.println("<TR>");
    out.println("<TD>"+tabla.getString(1)+"</TD>");
    out.println("</TR>"); };
    out.println("</TABLE></CENTER></DIV></HTML>");
    tabla.close(); instruccion.close(); canal.close();}
    catch(SQLException e) {};
    %>Results:
    CUSTOMER
    1
    2
    3
    4
    Doing the change in query:
    SELECT CUSTOMER_NAME FROM CUSTOMERS
    I have not results....
    Thank you.

    sorry, I misplaced an ending code bracket on last one
    I'm not really familiar with doing this inside a jsp.. but there are a few things that you should try to make sure that it isn't a database problem before assuming it is a problem on your jsp.... It is possible you have already tried the following but just to make sure.
    When you do the second query does the first two out.printlns that are before the while still output? If not then your query is incorrect.
    Second I would try
    String Query = "SELECT ID_CUSTOMER,CUSTOMER_NAME FROM CUSTOMERS";
    try { tabla = instruccion.executeQuery(Query);
    out.println("<TABLE Border=10 CellPadding=5><TR>");
    out.println("<TD>CUSTOMER_ID</TD><TD>CUSTOMER_NAME</TD></TR>");
    while(tabla.next()) {
    out.println("<TR>");
    out.println("<TD>"+tabla.getString(1)+"</TD>");
    out.println("<TD>"+tabla.getString(2)+"</TD>");
    out.println("</TR>"); };
    out.println("</TABLE></CENTER></DIV></HTML>");I suspect this will also return nothing.. if that is the case then you need to check your database. If it does infact return values for the ID and nothing for the NAME then I'm not sure at this point what the problem is.

  • Row value needs to be changes as column through SQL Query

    HI ALL
    I have a table like below
    ID Month VALUES
    1 01-jan 10
    1 01-feb 20
    2 01-jan 10
    2 01-feb 20
    I need the output like below
    ID 01-jan 01-feb
    1 10 20
    2 10 20
    How can i get it through SQL Query?. Please help me on that i have urgent work like this

    In effect because you are wanting to take X rows and squish them down to 1 row per id, you are gouping on the ID to typically a group by clause is the best way to do this.
    If you really wanted to do it without aggregate functions and a group by clause you would be looking for something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  WITH t as (select 1 as id, '01-jan' as month, 10 as val from dual union all
      2             select 1, '01-feb', 20 from dual union all
      3             select 1, '01-mar', 30 from dual union all
      4             select 2, '01-jan', 10 from dual union all
      5             select 2, '01-feb', 30 from dual union all
      6             select 2, '01-mar', 60 from dual)
      7  --
      8  select id, jan, feb, mar
      9  from (
    10    select id
    11          ,row_number() over (partition by id order by to_date(month,'dd-mon')) as rn
    12          ,val as jan
    13          ,lead(val) over (partition by id order by to_date(month,'dd-mon')) as feb
    14          ,lead(val,2) over (partition by id order by to_date(month,'dd-mon')) as mar
    15    from t
    16    )
    17* where rn = 1
    SQL> /
            ID        JAN        FEB        MAR
             1         10         20         30
             2         10         30         60
    SQL>Although this will only work if you can guarantee that there is a '01-jan' value for each id. If there could be missing values then you'll have to use aggregate functionality.

  • How to Create a new column from two different result sets

    How to Create a new column from two different result sets, both the result set uses the different date dimensions.

    i got solutions for this is apply filters in column formula it self, based on the requirement.

  • How to get the number of columns in a result set???

    hi everyone..
    i am trying to establish a servlet applet communication....
    my applet send the sql query to the servlet as serialised string and then the servlet executes the query...
    Since i need to pass the result back to the applet, i thaught of passing the whole reult set to the applet..but that seems to be not possible..
    so i thaught of storing my result set data in a vector and then pass the vector,but the first problem that i came across is that how to get the number of colums in a result set....
    so is there a way to get the number of columns in a result set...???
    and also i would like to know if it possible to send my whole result set to the applet bye serialization or by any method...???
    thanx in advance

    You shouldn't do. It expenses resources (you should always close the ResultSet and the Statement as fast as possible). Simply gently process it into a Collection or Map of DTO's. Those are serializable.

  • How to determine how many times result set columns have same value

    Hi -
    I'm doing a report which will be used for payment trend analyses.
    My initial result set looks like this:
    HOUSEHOLD_ID     JAN_PMT     FEB_PMT     MAR_PMT     APR_PMT     MAY_PMT     JUN_PMT     JUL_PMT     AUG_PMT     SEP_PMT     OCT_PMT     NOV_PMT     DEC_PMT
    90026845409     1     1     1     1     2     1     1     1     1     0     1     0(many rows, of course; result set pivoted)
    I need to determine the households that have a > 0 value in three or more consecutive months.
    I'm hoping someone will have some suggestions because the only solutions I'm coming up with right now would be a coding nightmare (lots of "OR's"), and I'm assuming (hoping) there's a better solution out there.
    Thanks!
    Christine

    Hi Frank,
    I'm not sure I'm understanding how I would use those analytic functions. Here is my select statement:
    SELECT HOUSEHOLD_ID,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  1 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  1 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS JAN_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  2 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  2 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS FEB_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  3 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  3 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS MAR_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  4 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  4 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS APR_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  5 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  5 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS MAY_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  6 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  6 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS JUN_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  7 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  7 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS JUL_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  8 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  8 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS AUG_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     =  9 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 =  9 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS SEP_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     = 10 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 10 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS OCT_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     = 11 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 11 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS NOV_PMT,
           SUM(CASE WHEN ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM'))     = 12 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 ) OR
                         ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'MM')) - 1 = 12 AND TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6  )
                    THEN 1 ELSE 0 END) AS DEC_PMT
      FROM MONETARY_TRANS
    WHERE MONETARY_TRANS_TYPE_ID    = 1                             --payment
    --TESTING
    AND HOUSEHOLD_ID = 90026845409
       AND RESPONSIBLE_PARTY_TYPE_ID = 1                             --household
       AND RECEIVED_DATE > '01-JAN-2008'
       AND ( TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) < 6
        OR   TO_NUMBER(TO_CHAR(RECEIVED_DATE, 'DD')) > 19 )
       AND PREMIUM_AMOUNT            > 0
       AND BILLING_TRANS_TYPE_ID     = 6
       AND MONETARY_TRANS_TYPE_ID    = 1
       AND RESPONSIBLE_PARTY_TYPE_ID = 1
    GROUP BY HOUSEHOLD_IDAnd from this I get the results originally posted. From there I need to figure out the households that have values greater than 0 for three or more consecutive months.
    Thanks for your help........
    -Christine

  • Change display of result set from 'showing data as rows, to showing data as one or more columns'

    Hi Everyone,
    I am interested in changing the way that data is displayed in my result set.
    Essentially I want to display a selection of rows (1 to n) as columns, the following diagram explains my intentions -
    Perhaps one of the greatest challenges here is the fact that I do not have a concrete number of rows (or BIN numbers).
    Each stock item could be stored in one or more BINS, which I will not know until running my query.
    Any suggestions here will be greatly appreciated.
    Kind Regards,
    David

    Can you explain on what basis you select those BinLabels? There're lots of other labels also available on your sample data so whats the rule which determines which all BinLabels should be selected?
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs
    Agree with Visakh16's opinion. In addition, it might be helpful if you can post your DDL here.
    Regards,
    Elvis Long
    TechNet Community Support

  • Unable to find specied column in result set.

    i m trying to display database values in textboxes on SelectedIndex_Changed event of list box control but i am getting "Unable to find specified column in result set" again n again..
    why this is so??????

    i have to create a new iview from the template of mdm iviews. then i was asked about the alias property.
    thanks,
    raghavendra

Maybe you are looking for