Help for efficient/better query

DB Details:
Oracle 11g R2 - 11.2.0.1
CREATE TABLE workflow_routing_assoc
    wf_routing_assoc_id   NUMBER,                                 -- unique id
    routing_group_id      NUMBER,        -- common id for the four combination
    routing_rule_id       NUMBER, -- this column differnciates the information provided eg: date,day,month,year
    routing_rule_value    VARCHAR2 (50 BYTE), -- this column contains the information for the routing_rule_id(third column) eg: 01(date),wed(day),month(sep),year(2011)
    created_by            VARCHAR2 (50 BYTE),              --created user name
    created_date          timestamp (6),                        --created date
    modified_by           VARCHAR2 (50 BYTE),           -- modifying user name
    modified_date         timestamp (6)
)                                                              --modified date
INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                    routing_group_id,
                                    routing_rule_id,
                                    routing_rule_value)
  VALUES   (1,
            55,
            8,
            'test-example');
INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                    routing_group_id,
                                    routing_rule_id,
                                    routing_rule_value)
  VALUES   (2,
            55,
            5,
            '12');
INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                    routing_group_id,
                                    routing_rule_id,
                                    routing_rule_value)
  VALUES   (3,
            55,
            2,
            'sep');
INSERT INTO workflow_routing_assoc (wf_routing_assoc_id,
                                    routing_group_id,
                                    routing_rule_id,
                                    routing_rule_value)
  VALUES   (4,
            55,
            9,
            '2010');
COMMIT;
-- NEED A BETTER QUERY INSTEAD OF THIS
*SQL> SELECT   result0.routing_group_id*
  *2    FROM   (SELECT   routing_group_id, routing_rule_id*
  *3              FROM   workflow_routing_assoc*
  *4             WHERE   routing_rule_value = 'test-example') result0,*
  *5           (SELECT   routing_group_id, routing_rule_id*
  *6              FROM   workflow_routing_assoc*
  *7             WHERE   routing_rule_value = '12') result1,*
  *8           (SELECT   routing_group_id, routing_rule_id*
  *9              FROM   workflow_routing_assoc*
*10             WHERE   routing_rule_value = 'sep') result2,*
*11           (SELECT   routing_group_id, routing_rule_id*
*12              FROM   workflow_routing_assoc*
*13             WHERE   routing_rule_value = '2010') result3*
*14   WHERE       result0.routing_rule_id = 8*
*15           AND result1.routing_rule_id = 5*
*16           AND result2.routing_rule_id = 2*
*17           AND result3.routing_rule_id = 9*
*18           AND result0.routing_group_id = result1.routing_group_id*
*19           AND result1.routing_group_id = result2.routing_group_id*
*20           AND result2.routing_group_id = result3.routing_group_id;*
op:
ROUTING_GROUP_ID
              55Thanks in advance

Hi,
What's wrong with the solution in the other thread?
Query simplification
Point out where it's getting the wrong results, and explain how you get the right results in those places. Post some new sample data and results if necessary.

Similar Messages

  • Need help for SQL SELECT query to fetch XML records from Oracle tables having CLOB field

    Hello,
    I have a scenario wherein i need to fetch records from several oracle tables having CLOB fields(which is holding XML) and then merge them logically to form a hierarchy XML. All these tables are related with PK-FK relationship. This XML hierarchy is having 'OP' as top-most root node and ‘DE’ as it’s bottom-most node with One-To-Many relationship. Hence, Each OP can have multiple GM, Each GM can have multiple DM and so on.
    Table structures are mentioned below:
    OP:
    Name                             Null                    Type        
    OP_NBR                    NOT NULL      NUMBER(4)    (Primary Key)
    OP_DESC                                        VARCHAR2(50)
    OP_PAYLOD_XML                           CLOB       
    GM:
    Name                          Null                   Type        
    GM_NBR                  NOT NULL       NUMBER(4)    (Primary Key)
    GM_DESC                                       VARCHAR2(40)
    OP_NBR               NOT NULL          NUMBER(4)    (Foreign Key)
    GM_PAYLOD_XML                          CLOB   
    DM:
    Name                          Null                    Type        
    DM_NBR                  NOT NULL         NUMBER(4)    (Primary Key)
    DM_DESC                                         VARCHAR2(40)
    GM_NBR                  NOT NULL         NUMBER(4)    (Foreign Key)
    DM_PAYLOD_XML                            CLOB       
    DE:
    Name                          Null                    Type        
    DE_NBR                     NOT NULL           NUMBER(4)    (Primary Key)
    DE_DESC                   NOT NULL           VARCHAR2(40)
    DM_NBR                    NOT NULL           NUMBER(4)    (Foreign Key)
    DE_PAYLOD_XML                                CLOB    
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    SELECT
    j.op_nbr||'||'||j.op_desc||'||'||j.op_paylod_xml AS op_paylod_xml,
    i.gm_nbr||'||'||i.gm_desc||'||'||i.gm_paylod_xml AS gm_paylod_xml,
    h.dm_nbr||'||'||h.dm_desc||'||'||h.dm_paylod_xml AS dm_paylod_xml,
    g.de_nbr||'||'||g.de_desc||'||'||g.de_paylod_xml AS de_paylod_xml,
    FROM
    DE g, DM h, GM i, OP j
    WHERE
    h.dm_nbr = g.dm_nbr(+) and
    i.gm_nbr = h.gm_nbr(+) and
    j.op_nbr = i.op_nbr(+)
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    I am using above SQL select statement for fetching the XML records and this gives me all related xmls for each entity in a single record(OP, GM, DM. DE). Output of this SQL query is as below:
    Current O/P:
    <resultSet>
         <Record1>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <DM_PAYLOD_XML1>
              <DE_PAYLOD_XML1>
         </Record1>
         <Record2>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML2>
              <DM_PAYLOD_XML2>
              <DE_PAYLOD_XML2>
         </Record2>
         <RecordN>
              <OP_PAYLOD_XMLN>
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XMLN>
         </RecordN>
    </resultSet>
    Now i want to change my SQL query so that i get following output structure:
    <resultSet>
         <Record>
              <OP_PAYLOD_XML1>
              <GM_PAYLOD_XML1>
              <GM_PAYLOD_XML2> .......
              <GM_PAYLOD_XMLN>
              <DM_PAYLOD_XML1>
              <DM_PAYLOD_XML2> .......
              <DM_PAYLOD_XMLN>
              <DE_PAYLOD_XML1>
              <DE_PAYLOD_XML2> .......
              <DE_PAYLOD_XMLN>
         </Record>
         <Record>
              <OP_PAYLOD_XML2>
              <GM_PAYLOD_XML1'>
              <GM_PAYLOD_XML2'> .......
              <GM_PAYLOD_XMLN'>
              <DM_PAYLOD_XML1'>
              <DM_PAYLOD_XML2'> .......
              <DM_PAYLOD_XMLN'>
              <DE_PAYLOD_XML1'>
              <DE_PAYLOD_XML2'> .......
              <DE_PAYLOD_XMLN'>
         </Record>
    <resultSet>
    Appreciate your help in this regard!

    Hi,
    A few questions :
    How's your first query supposed to give you an XML output like you show ?
    Is there something you're not telling us?
    What's the content of, for example, <OP_PAYLOD_XML1> ?
    I don't think it's a good idea to embed the node level in the tag name, it would make much sense to expose that as an attribute.
    What's the db version BTW?

  • Could do with help for a better expression

    Hi guys im using the following code to detect if a file is a text file it works however it is possible to fool it by having a file file.txt.doc. can anyone suggest a better way to do this? bear in mind its a javascript function.
    var filter = /.txt/;
         if (filter.test(str))

    > Hi guys im using the following code to detect if a
    file is a text file it works however it is possible
    to fool it by having a file file.txt.doc. can anyone
    suggest a better way to do this?         java.io.File file = new java.io.File("test.txt");
            if(file.exists() && file.getName().endsWith(".txt")) {
                System.out.println(file.getName()+" is a txt-file!");
    > bear in mind its a
    javascript function.
    Ah well, bear in mind that this is a Java forum.
    ; )

  • Need help for top n query

    Hi,
    I want to show top 3 salary records from emp table and I am using below query in oracle * plus. However I am getting an error saying, "FROM keyword not found where expected". I am not getting what mistake I am doing while writing this query. Can someone plz advice?
    Query:
    Select top 3 sal from emp;
    Thanks in advance.

    Hi,
    In Oracle, there is no TOP keyword. The usual way to do a top-N query in Oracle is to use an analytic function, such as RANK:
    WITH     got_r_num     AS
         SELECT     sal
         ,     ename, empno, ...     -- whatever columns you want
         ,     RANK () OVER (ORDER BY sal DESC)    AS r_num
         FROM     scott.emp
    SELECT       sal
    ,       ename, empno, ...     -- if wanted
    ,       r_num                -- if wanted
    FROM       got_r_num
    WHERE       r_num     <= 3
    ORDER BY  sal
    ;Depending on how you want to handle ties, ypu may want to add tie-breaking columns to the end of the analytic ORDER BY clause, and/or use ROW_NUMBER instead of RANK.

  • Required help for a query

    Hi All....
    Required help for one more query.
    I have a table with data like this:
    Cust_id Transaction_no
    111 1
    111 2
    111 3
    111 4
    111 5
    111 6
    222 7
    222 8
    333 9
    333 10
    333 11
    333 12
    I wrote the following query :
    select cust_id, ntile(3) over (order by cust_id) "Bucket" from trans_detls
    The output is like this :
    Cust_id Bucket
    111 1
    111 1
    111 1
    111 1
    111 2
    111 2
    222 2
    222 2
    333 3
    333 3
    333 3
    333 3
    The problem is that I dont want the cust_id to overlap in buckets. That is one cust_id should be present in only one bucket.
    Is this possible?
    Thanks in advance.
    Ameya

    Or Something like..
    SQL> select * from test;
            ID         NO
           111          1
           111          2
           111          3
           111          4
           111          5
           111          6
           222          7
           222          8
           333          9
           333         10
           333         11
           333         12
    12 rows selected.
    SQL> select id, ntile(3) over (order by rn) "Bucket"
      2  from(
      3      select id,row_number() over(partition by id order by no) rn
      4      from test);
            ID     Bucket
           111          1
           222          1
           333          1
           111          1
           222          2
           333          2
           111          2
           333          2
           111          3
           333          3
           111          3
           111          3
    12 rows selected.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Please help to modifiy this query for better performance

    Please help to rewrite this query for better performance. This is taking long time to execute.
    Table t_t_bil_bil_cycle_change contains 1200000 rows and table t_acctnumberTab countains  200000 rows.
    I have created index on ACCOUNT_ID
    Query is shown below
    update rbabu.t_t_bil_bil_cycle_change a
       set account_number =
           ( select distinct b.account_number
             from rbabu.t_acctnumberTab b
             where a.account_id = b.account_id
    Table structure  is shown below
    SQL> DESC t_acctnumberTab;
    Name           Type         Nullable Default Comments
    ACCOUNT_ID     NUMBER(10)                            
    ACCOUNT_NUMBER VARCHAR2(24)
    SQL> DESC t_t_bil_bil_cycle_change;
    Name                    Type         Nullable Default Comments
    ACCOUNT_ID              NUMBER(10)                            
    ACCOUNT_NUMBER          VARCHAR2(24) Y    

    Ishan's solution is good. I would avoid updating rows which already have the right value - it's a waste of time.
    You should have a UNIQUE or PRIMARY KEY constraint on t_acctnumberTab.account_id
    merge rbabu.t_t_bil_bil_cycle_change a
    using
          ( select distinct account_number, account_id
      from  rbabu.t_acctnumberTab
          ) t
    on    ( a.account_id = b.account_id
           and decode(a.account_number, b.account_number, 0, 1) = 1
    when matched then
      update set a.account_number = b.account_number

  • Search help for field in ABAP Query

    Hi Experts,
    For a particular field in standard table the search help(F4) is not maintained in the table level, which is used in a ABAP query.
    Is there any possibilities for user-defined Search help using InfoSet or Query?
    Please help me in this regard.
    Thanks in advance,
    Balaganesh.

    Hi Bala,
    I understand your question better now.  Since you mention standard selections I assume that your InfoSet is based on a logical database instead of a table join, direct read, or custom data retrieval program.  You are correct that the AT SELECTION-SCREEN ON VALUE REQUEST logic I mentioned earlier will not work for the standard selections of a logical database.  The system gives you an error when generating your InfoSet if you try to use the standard selection name (in ECC 5.0 at least).  I've tried various tricks to attempt to get it to work, but so far no luck. 
    You could, of course, use a different logical database as your InfoSet basis (e.g. VAV has a matchcode on VBAK-VBELN) or create your own data retrieval program and change your InfoSet to use the custom program instead of a logical database.  In the second case you wouldn't need to deal with standard selections at all.  I understand that these solutions are probably not what you need and, in the case of the custom data retrieval program, would be more complex (it may not be worth it to write a custom program just to allow F4 help... or maybe it would be... just depends). 
    Please keep us updated if you find a way to do it.  I'll also report back if I happen to discover a way.
    Best Regards,
    Jamie

  • Help for a query to add columns

    Hi,
    I need for a query where I should add each TableC value as an additional column.
    Please suggest...
    I have 3 tables (TableA, TableB, TableC). TableB stores TableA Id and TableC stores TableB Id
    Considering Id of TableA.
    Sample data
    TableA     :          
    ID     NAME     TABLENAME     ETYPE
    23     Name1     TABLE NAMEA     Etype A
    TableB     :          
    ID     A_ID     RTYPE     RNAME
    26     23     RTYPEA     RNAMEA
    61     23     RTYPEB     RNAMEB
    TableC     :          
    ID     B_ID     COMPNAME     CONC
    83     26     Comp Name AA     1.5
    46     26     Comp Name BB     2.2
    101     61     Comp Name CC     4.2
    Scenario 1: AS PER ABOVE SAMPLE DATA Put each TableC value as an additional column.
    For an Id in TableA(23) where TableB contains 2 records of A_ID (26, 61) and TableC contains 2 records for 26 and 1 record for 61.
    Output required: Put each TABLEC value as an additional column
    TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME     TableC_1_CONC TableC_2_COMPNAME     TableC_2_CONC     
    Name1 EtypeA RTypeA Comp Name AA 1.5 Comp Name BB 2.2     so on..
    Name1 EtypeA RTypeB Comp Name CC 4.2 NULL NULL     
    Scenario 2: If Table C contains ONLY 1 row for each Id in TableB, output should be somewhat
    Output:
    TableA.NAME TableA.ETYPE TableB.RTYPE TableC_1_COMPNAME
    TableC_1_CONCvalue     value     value     value               value

    Hi,
    Welcome to the forum!
    Do you want the data from TableC presented
    (1) in one column, or
    (2) in several columns (a different column of results for each row in the original TableC)?
    (1) Is called String Aggregation and is easier than (2).
    The best way to do this is with a user-defined aggregate function (STRAGG) which you can copy from asktom.
    Ignoring TableA for now, you could get what you want by saying
    SELECT    b.rtype
    ,         STRAGG (   c.compname
                     || ' '
                     || c.conc
                     )  AS c_data
    FROM      TableB  b
    JOIN      TableC  c  ON b.id  = c.b_id
    GROUP BY  b.rtype;(2) Presenting N rows of TableC as it they were N columns of the same row is called a pivot. Search for "pivot" or "rows to columns" to find examples of how to do this.
    The number of columns in a result set is hard-coded into the query. If you don't know ahead of time how many rows in TableC will match a row in TableB, you can:
    (a) guess high (for example, hard-code 20 columns and let the ones that never contain a match be NULL) or,
    (b) use Dynamic SQL to write a query for you, which has exactly as many columns as you need.
    The two scripts below contain basic information on pivots.
    This first script is similar to what you would do for case (a):
    --     How to Pivot a Result Set (Display Rows as Columns)
    --     For Oracle 10, and earlier
    --     Actually, this works in any version of Oracle, but the
    --     "SELECT ... PIVOT" feature introduced in Oracle 11
    --     is better.  (See Query 2, below.)
    --     This example uses the scott.emp table.
    --     Given a query that produces three rows for every department,
    --     how can we show the same data in a query that has one row
    --     per department, and three separate columns?
    --     For example, the query below counts the number of employess
    --     in each departent that have one of three given jobs:
    PROMPT     ==========  0. Simple COUNT ... GROUP BY  ==========
    SELECT     deptno
    ,     job
    ,     COUNT (*)     AS cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ,          job;
    Output:
        DEPTNO JOB              CNT
            20 CLERK              2
            20 MANAGER            1
            30 CLERK              1
            30 MANAGER            1
            10 CLERK              1
            10 MANAGER            1
            20 ANALYST            2
    PROMPT     ==========  1. Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno;
    --     Output:
        DEPTNO ANALYST_CNT  CLERK_CNT MANAGER_CNT
            30           0          1           1
            20           2          2           1
            10           0          1           1
    --     Explanation
    (1) Decide what you want the output to look like.
         (E.g. "I want a row for each department,
         and columns for deptno, analyst_cnt, clerk_cnt and manager_cnt)
    (2) Get a result set where every row identifies which row
         and which column of the output will be affected.
         In the example above, deptno identifies the row, and
         job identifies the column.
         Both deptno and job happened to be in the original table.
         That is not always the case; sometimes you have to
         compute new columns based on the original data.
    (3) Use aggregate functions and CASE (or DECODE) to produce
         the pivoted columns. 
         The CASE statement will pick
         only the rows of raw data that belong in the column.
         If each cell in the output corresponds to (at most)
         one row of input, then you can use MIN or MAX as the
         aggregate function.
         If many rows of input can be reflected in a single cell
         of output, then use SUM, COUNT, AVG, STRAGG, or some other
         aggregate function.
         GROUP BY the column that identifies rows.
    PROMPT     ==========  2. Oracle 11 PIVOT  ==========
    WITH     e     AS
    (     -- Begin sub-query e to SELECT columns for PIVOT
         SELECT     deptno
         ,     job
         FROM     scott.emp
    )     -- End sub-query e to SELECT columns for PIVOT
    SELECT     *
    FROM     e
    PIVOT     (     COUNT (*)
              FOR     job     IN     ( 'ANALYST'     AS analyst
                             , 'CLERK'     AS clerk
                             , 'MANAGER'     AS manager
    NOTES ON ORACLE 11 PIVOT:
    (1) You must use a sub-query to select the raw columns.
    An in-line view (not shown) is an example of a sub-query.
    (2) GROUP BY is implied for all columns not in the PIVOT clause.
    (3) Column aliases are optional. 
    If "AS analyst" is omitted above, the column will be called 'ANALYST' (single-quotes included).
    {code}
    The second script, below, shows one way of doing a dynamic pivot in SQL*Plus:
    {code}
    How to Pivot a Table with a Dynamic Number of Columns
    This works in any version of Oracle
    The "SELECT ... PIVOT" feature introduced in Oracle 11
    is much better for producing XML output.
    Say you want to make a cross-tab output of
    the scott.emp table.
    Each row will represent a department.
    There will be a separate column for each job.
    Each cell will contain the number of employees in
         a specific department having a specific job.
    The exact same solution must work with any number
    of departments and columns.
    (Within reason: there's no guarantee this will work if you
    want 2000 columns.)
    Case 0 "Basic Pivot" shows how you might hard-code three
    job types, which is exactly what you DON'T want to do.
    Case 1 "Dynamic Pivot" shows how get the right results
    dynamically, using SQL*Plus. 
    (This can be easily adapted to PL/SQL or other tools.)
    PROMPT     ==========  0. Basic Pivot  ==========
    SELECT     deptno
    ,     COUNT (CASE WHEN job = 'ANALYST' THEN 1 END)     AS analyst_cnt
    ,     COUNT (CASE WHEN job = 'CLERK'   THEN 1 END)     AS clerk_cnt
    ,     COUNT (CASE WHEN job = 'MANAGER' THEN 1 END)     AS manager_cnt
    FROM     scott.emp
    WHERE     job     IN ('ANALYST', 'CLERK', 'MANAGER')
    GROUP BY     deptno
    ORDER BY     deptno
    PROMPT     ==========  1. Dynamic Pivot  ==========
    --     *****  Start of dynamic_pivot.sql  *****
    -- Suppress SQL*Plus features that interfere with raw output
    SET     FEEDBACK     OFF
    SET     PAGESIZE     0
    SPOOL     p:\sql\cookbook\dynamic_pivot_subscript.sql
    SELECT     DISTINCT
         ',     COUNT (CASE WHEN job = '''
    ||     job
    ||     ''' '     AS txt1
    ,     'THEN 1 END)     AS '
    ||     job
    ||     '_CNT'     AS txt2
    FROM     scott.emp
    ORDER BY     txt1;
    SPOOL     OFF
    -- Restore SQL*Plus features suppressed earlier
    SET     FEEDBACK     ON
    SET     PAGESIZE     50
    SPOOL     p:\sql\cookbook\dynamic_pivot.lst
    SELECT     deptno
    @@dynamic_pivot_subscript
    FROM     scott.emp
    GROUP BY     deptno
    ORDER BY     deptno
    SPOOL     OFF
    --     *****  End of dynamic_pivot.sql  *****
    EXPLANATION:
    The basic pivot assumes you know the number of distinct jobs,
    and the name of each one.  If you do, then writing a pivot query
    is simply a matter of writing the correct number of ", COUNT ... AS ..."\
    lines, with the name entered in two places on each one.  That is easily
    done by a preliminary query, which uses SPOOL to write a sub-script
    (called dynamic_pivot_subscript.sql in this example).
    The main script invokes this sub-script at the proper point.
    In practice, .SQL scripts usually contain one or more complete
    statements, but there's nothing that says they have to.
    This one contains just a fragment from the middle of a SELECT statement.
    Before creating the sub-script, turn off SQL*Plus features that are
    designed to help humans read the output (such as headings and
    feedback messages like "7 rows selected.", since we do not want these
    to appear in the sub-script.
    Turn these features on again before running the main query.
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Require help for a query

    Hi all..
    I required some help in writing a query..
    My table is like this
    Cust_id     Cust_type Del_status Incharge
    111     Gold     HD          
    222     Gold     
    333     Gold     HD
    444     Gold
    123     Gold     HD          
    456     Gold          
    789     Gold     HD
    987     Gold          
    555     Silver     HD
    666     Silver     HD
    777     Silver
    888     Silver
    I want a query to generate this output
    Cust_id     Cust_type Del_status Incharge
    111     Gold     HD     1
    222     Gold          1
    333     Gold     HD      1
    444     Gold          1
    555     Silver     HD     1
    777     Silver          1
    123     Gold     HD     2
    456     Gold          2
    789     Gold     HD     2
    987     Gold          2
    666     Silver     HD     2
    888     Silver          2
    The query basically allocates the customers to incharges... based on cust_type and del_status.
    there are 3 categories, Gold Customers, Silver Customers and HD customers..
    It should divide this three equally amongst the 2 incharges...
    Also this is just a sample data... actually table consists of around 3Lac customers and 12 incharges
    Sorry if its a incorrect post..
    Thanks in advance..

    Is there a way to find the value for ntile(2) dynamically?
    I tried something like
    Connected to:
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.8.0 - Production
    SQL> with mytable as (select 111 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
      2  select 222 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
      3  select 333 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
      4  select 444 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
      5  select 123 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
      6  select 456 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
      7  select 789 cust_id, 'Gold' cust_type, 'HD' del_status from dual UNION ALL
      8  select 897 cust_id, 'Gold' cust_type, null del_status from dual UNION ALL
      9  select 555 cust_id, 'Silver' cust_type, 'HD' del_status from dual UNION ALL
    10  select 666 cust_id, 'Silver' cust_type, 'HD' del_status from dual UNION ALL
    11  select 777 cust_id, 'Silver' cust_type, null del_status from dual UNION ALL
    12  select 888 cust_id, 'Silver' cust_type, null del_status from dual UNION ALL
    13  select 1001 cust_id, 'Copper' cust_type, null del_status from dual UNION ALL
    14  select 1002 cust_id, 'Copper' cust_type, 'HD' del_status from dual UNION ALL
    15  select 1003 cust_id, 'Copper' cust_type, null del_status from dual
    16  )
    17  select t1.cust_id
    18  , t1.cust_type
    19  , t1.del_status
    20  --, ntile(3) over (partition by nvl(t1.del_status,t1.cust_type) order by t1.cust_id)
    21  , ntile((select count(distinct nvl(t2.del_status,t2.cust_type))-1 from mytable t2)) over (parti
    tion by nvl(del_status,cust_type) order by cust_id)
    22  incharge
    23  from mytable t1
    24  order by incharge, t1.cust_type, t1.cust_id
    25  /
    , ntile((select count(distinct nvl(t2.del_status,t2.cust_type))-1 from mytable t2)) over (partition
    ERROR at line 21:
    ORA-30488: argument should be a function of expressions in PARTITION BY
    SQL> The number of incharges could change during the time.
    Message was edited by:
    Sven Weller

  • Plz help me in this query for the tree

    hi All
    I want to bulid tree that start with for example
    schema name "scott"
    then table "dept,emp
    then ename in table emp
    root scott
    parent dept
    child emp_name
    please help me in the query ?

    user222 wrote:
    any help my dearsIf you can draw one simple tree example. Then it will be easy to create query. Because i am confuse about the output. Just draw one example of your desired output tree. Then it will help to find solution.
    And while writing query or any example so use the 6 digit before and after your query or example to keep the formatting in orignal format. Otherwise it becomes hard to read.
    For more information see FAQ on right corner for page.
    -Ammad                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Search help for OBJECT ID with Text Description for a query

    I need to create search help for the field object text in HRP1000 - P1000-STEXT table in an infoset based on LDB PCH. Can anyone help me? I want it to appear on the adhoc query screen.
    Thanks,

    look at search help FC_RFCDEST. that problem has already been solved with this search help.

  • Please Help for the Query

    Please Help for the Query
    Hi frds please help me for the below query.What I want to do is to pull out the data from below table :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/18/2008 3IINFOTECH -4
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    as such :-
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3
    Here I want to find the Trend i.e either asc or desc order from the lowest indicator.
    In the above sample data -8, -4, -5, -3 out of which I want the asc order data -8, -5, -3 and exclude -4 data.Because the asc order -8, -5, -3 will not follow.
    So I want the data
    date ticker indicator
    03/13/2008 3IINFOTECH -8
    03/25/2008 3IINFOTECH -5
    03/27/2008 3IINFOTECH -3

    SQL> CREATE TABLE BORRAME(FECHA DATE, INDICA VARCHAR2(100));
    Tabla creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/13/2008','MM/DD/YYYY'), '3IINFOTECH -8');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/18/2008','MM/DD/YYYY'), '3IINFOTECH -4');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/25/2008','MM/DD/YYYY'), '3IINFOTECH -5');
    1 fila creada.
    SQL> INSERT INTO BORRAME VALUES(TO_DATE('03/27/2008','MM/DD/YYYY'), '3IINFOTECH -3');
    1 fila creada.
    SQL> COMMIT;
    Validación terminada.
    SQL>
    SQL> SELECT FECHA, INDICA
      2  FROM BORRAME
      3  WHERE SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) <> '4'
      4  ORDER BY SUBSTR(INDICA,INSTR(INDICA,'-',1)+1,LENGTH(INDICA)) DESC;
    FECHA                                                                
    INDICA                                                               
    13/03/08                                                             
    3IINFOTECH -8                                                        
    25/03/08                                                             
    3IINFOTECH -5                                                        
    27/03/08                                                             
    3IINFOTECH -3                                                        
                    

  • SQ01 Query Help for (MKPF and MSEG)

    Is their anyway to have the field MSEG-ERFMG show up on the query results as postive or negative color or use a "-" or "+".  Need to try and show whether is was a negative or postive movement.

    F1 help for MSEG-SHKZG
    Debit/credit indicator in revaluation
    This indicator is used for internal program control.
    Please do not change the entry in this field.
    Any changes made could lead to program errors or terminations.
    I guess the "sign" is defined trough this field ("S" - sollen (debit), "H" - haben (credit)). If my assumption is true, you won't be able to see + / - in MSEG-ERFMG simply because this field contains no information on the sign.
    Using ABAP code you can solve it (or in SQ01 you can use calculated field in your query...I'm not sure you can define that calculated field to cover your requirement...).
    Regards,
    Csaba
    Edited by: Csaba Szommer on May 12, 2009 11:20 PM

  • When iWorks for iCloud Beta become available I subscribed to it. After that I become unable to access iCloud at all as in all my devices I get messages to install it and other apps (find my phone, etc) that are already active. Anyone could help?

    When iWorks for iCloud Beta become available I subscribed to it. After that I become unable to access iCloud at all as in all my devices I get messages to install it and other apps (find my phone, etc) that are already active. Anyone could help?

    The first time an iPhone is connected to iTunes that is used to sync with another iPhone or iOS device, you are prompted to transfer the backup for the other iPhone or iOS device or to set up the iPhone as a new iPhone.
    The former does as provided - it transfers the backup for the other iPhone or iOS device to the iPhone replacing all data on the iPhone that is included with the backup being transferred. The latter does nothing allowing you to make your various selections for the iPhone sync preferences with iTunes.
    This is designed to be done right away with a new iPhone.
    If you don't have a backup for the iPhone with iTunes on your computer and don't have an iCloud backup that hasn't been updated since choosing to transfer the backup for your iPod Touch to the iPhone, the data that was on the iPhone is gone.

  • Creating search help for a field in AdHoc Query

    Hi
    We have created an infoset based on LDB PCH.
    (The infoset contains object type O only).
    For the object-id field the users want search help when choosing this field for selection.
    Using "start via selection screen" does not give a good solution.
    Can anyone explain how I can create search help for fields in an infoset?
    Regards
    Kirsten

    Hi
    We have created an infoset based on LDB PCH.
    (The infoset contains object type O only).
    For the object-id field the users want search help when choosing this field for selection.
    Using "start via selection screen" does not give a good solution.
    Can anyone explain how I can create search help for fields in an infoset?
    Regards
    Kirsten

Maybe you are looking for

  • Since installing Yosemite, my MacBook Pro has become slower.  Is there any way to fix this problem?

    Ever since I installed OS X Yosemite on my mid 2012 MacBook Pro, it has started becoming slower and slower and glitching out.  Is there any way to fix this?  Here is my diagnostics: Problem description: My Mac is rather slow.  It started happening af

  • Working on a CS4 project in CS5.5 - Flash won't let me save FLA normally (ctrl+s)

    I started working on a Flash project and I'll be moving it back and  forth between two different computers. The project was originally  started in Flash CS4. The other computer has Flash CS5.5 installed. So  when in CS5.5 I save the fla as a CS4 vers

  • Mixed firewire devices

    I am planning on purchasing a new MacPro in the next month. I currently have some Firewire 400 devices. Are there any issues daisy chaining Firewire 400 and 800 devices together? If the 800 devices are first will they still run at the higher speed or

  • Mass cancellation IW47

    Hello, Please I would like to know if is possible to use the action mass cancellation confirmation through the transaction IW47. When I run the transaction IW47 the system generate a list of confirmation, and if I try to get a mass cancellation of co

  • Video taping on iPad

    I am trying to video tape a 60 minute segment, but my iPad stops at 50 minutes, saying that's all the time allowed.  Is there any way to tape for longer than 50 minutes?  I bought extra storage space in the cloud, which made no difference. :(  Any id