Query complex REGEXP LISTAGG

Hello world

I have a problem with a complex regular expression, maybe I'm over complicating it.

Essentially, what I have is some interactions, interaction can go to several queues over time, what I need to achieve is when the queue of the item is listed as WORKBIN or OFFICE I want to find the queue that was before that. Things get complicated, because sometimes I have an example where he goes queue > QUEUE > WORKBIN > TAIL > DESKTOP >TAIL> WORKBIN I need to find the line in "BOLD".

What I tried was the LISTAGG a partition of interactions for a list as a QUEUE. QUEUE | WORKBIN | QUEUE | DESKTOP COMPUTER | QUEUE: WORKBIN can use REGEXP_INSTR to cut the chain out, but I can't seem to find the latest iteration of the expression.

Here is an example of the data:

queue of the date interaction_id

1037150 2015-01-20 18:35:57 HMB_SITEL_BASIC_IXNQ

1037150 2015-01-20 20:59:47 desktop_in_progress

1037150 2015-01-20 21:44:18 TFR_HMB_SITELBASIC_IXNQ

1037150 2015-01-21 07:54:30 desktop_in_progress

1037150 2015-01-21 07:56:40 NO

1037150 2015-01-21 07:56:40 desktop_in_progress

And the statement that I have tried:

UBSTR (SUBSTR ('|)) ' || LISTAGG (LAST_QUEUE_NAME, ' |') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ', 1, REGEXP_INSTR ('|) ' || LISTAGG(LAST_QUEUE_NAME, '|') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ((',' desktop_in_progress', 1-2), INSTR (SUBSTR ('|)) ' || LISTAGG (QUEUE_NAME, ' |') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ', 1, REGEXP_INSTR ('|) ' || LISTAGG(QUEUE_NAME, '|') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ((',' desktop_in_progress ', 1-2),' | (',-1) + 1, REGEXP_INSTR ('|) ' || LISTAGG(QUEUE_NAME, '|') Group (order of AGENT_END_TS) on (INTERACTION_ID score) |' | ((',' desktop_in_progress', 1-2)

Any help or suggestions appreciated

Thomas

Select min (rn) of


with

data in the form of

(select 1037150 interaction_id, to_date ('2015-01-20 18:35:57 ',' yyyy-mm-dd hh24:mi:ss') date_, 'HMB_SITEL_BASIC_IXNQ' queue_ of all the double union)

Select 1037150, to_date ('2015-01-20 20:59:47 ',' yyyy-mm-dd hh24:mi:ss'), 'desktop_in_progress' from dual union all

Select 1037150, to_date ('2015-01-20 21:44:18 ',' yyyy-mm-dd hh24:mi:ss'), 'TFR_HMB_SITELBASIC_IXNQ' from dual union all

Select 1037150, to_date ('2015-01-21 07:54:30 ',' yyyy-mm-dd hh24:mi:ss'), 'desktop_in_progress' from dual union all

Select 1037150, to_date ('2015-01-21 07:56:40 ',' yyyy-mm-dd hh24:mi:ss'), 'NONE' from dual union all

Select 1037150, to_date ('2015-01-21 07:56:40 ',' yyyy-mm-dd hh24:mi:ss'), 'desktop_in_progress' from dual

)

Select interaction_id, to_char (date_, 'yyyy-mm-dd hh24:mi:ss') date_, queue_,.

cases where instr (upper (queue_), 'WORKBENCH') = 0

and instr (upper (queue_), 'DESKTOP') = 0

and instr (upper (queue_), 'NONE') = 0

then row_number() over (partition by interaction_id by date_ desc order)

end RN

from the data

order of interaction_id, date_

INTERACTION_ID DATE_ QUEUE_ RN
1037150 2015-01-20 18:35:57 HMB_SITEL_BASIC_IXNQ 6
1037150 2015-01-20 20:59:47 desktop_in_progress -
1037150 2015-01-20 21:44:18 TFR_HMB_SITELBASIC_IXNQ 4
1037150 2015-01-21 07:54:30 desktop_in_progress -
1037150 2015-01-21 07:56:40 NONE -
1037150 2015-01-21 07:56:40 desktop_in_progress -

Concerning

Etbin

Tags: Database

Similar Questions

  • Query complex Question

    I'm making a 9-1-1 information system. I select the Agency calls and the type of call for a given month. That works fine, but I need them Imprimeen desending sequence by call number up to now call type. Don't see anyway to do this with a single query.
    Is this a way? If this is not the case, the second part of this question is that I have not created a table using SQL. I need 3 fields, Field_A is the text (9 positions); Field_B is the text (40 posts) and the last is the number of my summary of the request. How to create a table to support this function?

    Query
    < cfquery name = "GetEventCount" datasource = "JasperCountyDB" >
    Select count (AG_ID) as EventCount, TYCOD, TYP_ENG, CURENT
    of aeven
    where ((AG_ID = '#Session.InquiryAgencyCode#'))
    AND (CURENT = 't') AND (CAD LIKE "#EventReportDate #"))
    Group of AG_ID, TYCOD, TYP_ENG, CURENT
    < / cfquery >

    Thanks for any guideance you can provide.
    Ron

    Phil

    Thanks, that solved my problem. Is there a good book SQL which penetrates into the more complex queries and joins of tables, etc. ?

    Thanks again
    Ron

  • query complex to solve

    Hello!
    any body can solve this please
    I have two tables

    ITEM_MASTER

    POINT NON-NULL VARCHAR2 (25)
    ITEM_NUMBER_TYPE NOT NULL VARCHAR2 (6)
    DEPT NOT NULL NUMBER 4
    CLASS NOT NULL NUMBER 4
    SUBCLASS NOT NULL NUMBER 4
    STATUS NOT NULL VARCHAR2 (1)
    ITEM_DESC NOT NULL VARCHAR2 (250)

    rpm_item_zone_price

    ITEM_ZONE_PRICE_ID NOT NULL NUMBER (15)
    POINT NON-NULL VARCHAR2 (25)
    ZONE_ID NOT NULL NUMBER (10)
    STANDARD_RETAIL NULL undetermined (20.4) - price column
    that looks like this

    where zone_id to understand
    When zone_id = 1 then 'Express '.
    When zone_id = 2 then 'Superstore '.
    When zone_id = 3 then 'Metro '.

    and I need a query based on this condition

    Express price is higher or lower than the price metro, price Express less large price surfaces

    How can write us a query for this can any body can give an idea as soon as POSSIBLE please

    I do not know the o/p, give me an idea

    Published by: [email protected] on June 18, 2010 12:14 AM

    Hello

    This is not a complex query, if we know exactly what we have and what we want!

    If I understand correctly, you need a query that displays the details of the elements for items that have a "higher or lower priced metro" express price (this means do not equal?) OR
    with an express price< superstores="" price="">
    If we assume that each component has 3 different prices defined, we could use this:

    select im.* from item_master im, rpm_item_zone_price zp1,rpm_item_zone_price zp2,rpm_item_zone_price zp3
    where zp1.item=im.item
    and   zp2.item=im.item
    and   zp3.item=im.item
    and   zp1.zone_id = 1
    and   zp2.zone_id = 2
    and   zp3.zone_id = 3
    and   ((zp1.standard_retail!=zp3.standard_retail) or
           (zp1.standard_retail
    
  • Query complex hierarhical

    Hi, Evereyone.
    Help me, please.
    I have two tables:
    create table GROUP_TEST (
    AA_ID number, //This is just synthetic ID
    GTID VARCHAR2(10), //This is test natural ID of group test
    GTTST_0 VARCHAR2(10), //This is ID of test component
    GTTST_1 VARCHAR2(10), //This is ID of test component
    GTTST_2 VARCHAR2(10), //This is ID of test component
    GTTST_3 VARCHAR2(10)); //This is ID of test component
    
    create table TEST(
    AA_ID number, //This is just synthetic ID
    ITID VARCHAR2(10), //This is test natural ID
    TYPE VARCHAR2(1));  //Can be 'G' for group test, or 'I' - individual test
    And we have data in it:
    INSERT INTO "TEST" (AA_ID, ITID, ITGT) VALUES ('4', 'T4', 'I');
    INSERT INTO "TEST" (AA_ID, ITID, ITGT) VALUES ('3', 'T3', 'I');
    INSERT INTO "TEST" (AA_ID, ITID, ITGT) VALUES ('2', 'T2', 'I');
    INSERT INTO "TEST" (AA_ID, ITID, ITGT) VALUES ('1', 'T1', 'I');
    
    
    INSERT INTO "TEST" (AA_ID, ITID, ITGT) VALUES ('7', 'G3', 'G');
    INSERT INTO "TEST" (AA_ID, ITID, ITGT) VALUES ('6', 'G2', 'G');
    INSERT INTO "TEST" (AA_ID, ITID, ITGT) VALUES ('5', 'G1', 'G');
    
    INSERT INTO "GROUP_TEST" (AA_ID, GTID, GTTST_0, GTTST_1) VALUES ('3', 'G3', 'T3', 'T4');
    INSERT INTO "GROUP_TEST" (AA_ID, GTID, GTTST_0, GTTST_1) VALUES ('2', 'G2', 'T2', 'G3');
    INSERT INTO "GROUP_TEST" (AA_ID, GTID, GTTST_0, GTTST_1) VALUES ('1', 'G1', 'T1', 'G2');
    As you can see, some some may consist of a group test group tests or some individual test.
    Now we have a tree:
    G1 consists of T1 and G2
    G2 is made up of T2 and G3
    G3 consists of T3 and T4

    I want to select all components of lowest level (individul tests) for each test group.
    This means that in the output should be:
    GR_AA_ID               GR_GRID    IT_AA_ID               IT_ITID    IT_TYPE 
    ---------------------- ---------- ---------------------- ---------- ------- 
    1                      G1         1                      T1         I       
    1                      G1         2                      T2         I       
    1                      G1         3                      T3         I       
    1                      G1         4                      T4         I       
    2                      G2         2                      T2         I       
    2                      G2         3                      T3         I       
    2                      G2         4                      T4         I       
    3                      G3         3                      T3         I       
    3                      G3         4                      T4         I       
    
    9 rows selected
    Is it possible to get this result?
    Thank you!

    Published by: JustasVred on June 15, 2010 04:36

    The reason why it is 'complex' and is not simple, because of your non-standard data model.
    The columns of gttst is repeated in the table group_test. To build your hierarchy, ideally this should be fixed in your datamodel, but here I fixed it within my query.
    In real life, you want to take CPU cycles at this problem every time the query is executed.

    SQL> with group_test_reformatting as
      2  ( select aa_id
      3         , gtid itid_parent
      4         , case l
      5           when 1 then gttst_0
      6           when 2 then gttst_1
      7           when 3 then gttst_2
      8           when 4 then gttst_3
      9           end itid_child
     10      from group_test
     11           cross join (select level l from dual connect by level <= 4)
     12  )
     13  , group_test_reformatted as
     14  ( select *
     15      from group_test_reformatting
     16     where itid_child is not null
     17  )
     18   select connect_by_root gt.aa_id       as gr_aa_id
     19        , connect_by_root gt.itid_parent as gr_grid
     20        , t_child.aa_id                  as it_aa_id
     21        , t_child.itid                   as it_itid
     22        , t_child.itgt                   as it_itgt
     23     from group_test_reformatted gt
     24          inner join test t_parent on (gt.itid_parent = t_parent.itid)
     25          inner join test t_child on (gt.itid_child = t_child.itid)
     26    where connect_by_isleaf = 1
     27  connect by gt.itid_parent = prior gt.itid_child
     28    start with t_parent.itgt = 'G'
     29    order by gr_grid
     30        , it_itid
     31  /
    
      GR_AA_ID GR_GRID      IT_AA_ID IT_ITID    I
    ---------- ---------- ---------- ---------- -
             1 G1                  1 T1         I
             1 G1                  2 T2         I
             1 G1                  3 T3         I
             1 G1                  4 T4         I
             2 G2                  2 T2         I
             2 G2                  3 T3         I
             2 G2                  4 T4         I
             3 G3                  3 T3         I
             3 G3                  4 T4         I
    
    9 rows selected.
    

    Kind regards
    Rob.

  • Query complex Oracle reports

    Hi friends,

    I'm a newbie on the oracle reports. I'm asking to revise/debug a complex report.
    It's the source of the report query Oracle:
    select  mta.transaction_date,
            &P_acct_flex,      
            DECODE(mta.transaction_source_type_id,1,to_char(mmt.transaction_source_id),2,&P_so_flex,
                   mmt.transaction_source_name) Source
     
    from
           mtl_system_items            msi,  
           &C_from_cat  
           &C_from_type
           &C_source_from
           mtl_material_transactions   mmt,
           gl_code_combinations        gcc,
           MTL_SALES_ORDERS            mkts,
           MTL_GENERIC_DISPOSITIONS    mdsp,
           GL_CODE_COMBINATIONS        gl,
           mtl_transaction_accounts    mta
    where   mta.transaction_id = mmt.transaction_id
           and  &P_where_acct
           and  &P_where_item
           and  &P_where_cat 
                &C_where_cat 
                &C_where_type
           and  msi.organization_id = :P_org_id
                &P_date_range
                &C_where_value
                &C_where_subinv
                &C_where_reason
                &C_source_where
    /
    I want to first test the reports in SQL * most environment but I struggle to be replaced by many variables :(
    How can I replace these variables and what kind of data can I put in a
    My question is:

    1. What is the difference of the variable & variable and: variable?, they are the two variables of parameter and need of entry of the form parameter during execution?

    2. starting at the last part of the query
           and  msi.organization_id = :P_org_id
                &P_date_range
                &C_where_value
                &C_where_subinv
                &C_where_reason
                &C_source_where
    How can I replace the variables here? I expect the 'operators' between them, but there are none.
    I can do the request under the form 'and msi.oraganization_id = & P_org_id' instead of ' and msi.oraganization_id =: P_org_id?

    Help, please...

    Thank you very much

    MSK

    Published by: yxes2009 on January 11, 2010 20:07

    Use Toad here if you can. It is easier to assign values for: p or & var.

    1. What is the difference of the variable & variable and: variable?, they are the two variables of parameter and need of entry of the form parameter during execution?

    DM did.

    2. starting at the last part of the query

    and msi.organization_id =: P_org_id
    & P_date_range
    & C_where_value
    & C_where_subinv
    & C_where_reason
    & C_source_where

    How can I replace the variables here?

    Don't forget that substitutes makes sense. For example: P_org_id can be 123 and & P_date_range may be 1 = 1 or ' and... between... and... "etc.

  • Error creating the pie chart to 3D with query complex.

    Hi all

    I tried to create a pie 3D with the following query:

    SELECT THE NULL LINK,

    LABEL CRITERIA,

    DIGITAL VALUE

    Of

    (SELECT CRITERIA, COUNT (*) AS 'NUMBER'

    DE)

    SELECT AIRCRAFT_REGO AS "REGO",.

    'HOLD OPEN' as "CRITERIA", he said.

    CNTOPEN AS 'COUNT '.

    OF UTEV0001 HAS

    INNER JOIN (select ACFTABB, count (ACFTABB) as CNTOPEN)

    of SIMLOG

    "where ACDFRCYC = s"

    AND OPENHODM = 'O'

    AND ACDFITMX = 'Y '.

    ACFTABB GROUP

    order of ACFTABB) B

    ON B.ACFTABB = A.AIRCRAFT_REGO

    WHERE AUDTCURI = 'C '.

    UNION

    SELECT AIRCRAFT_REGO AS "REGO",.

    "NOT PROCESSED" as of "CRITERIA", he said.

    CNTACTN AS 'COUNT '.

    OF UTEV0001 X

    JOIN IN-HOUSE

    (select ACFTABB, count (ACFTABB) as CNTACTN

    of SIMLOG

    "where ACDFRCYC = s"

    AND ACDFATN = "

    AND AFFECTED = "

    ACFTABB GROUP

    order of ACFTABB) C

    ON X.AIRCRAFT_REGO = C.ACFTABB

    WHERE AUDTCURI = 'C '.

    UNION

    SELECT AIRCRAFT_REGO AS "REGO",.

    "FAILURE to KNOWN" as "CRITERIA", he said.

    CNTKNOW AS 'COUNT '.

    OF UTEV0001 Y

    INNER JOIN (SELECT ACFTABB, COUNT (ACFTABB) AS CNTKNOW

    OF SIMLOG

    WHERE ACDFRCYC = S"

    AND AFFECTED = 'DEVELOPMENT '.

    ACFTABB GROUP

    order of ACFTABB) D

    ON Y.AIRCRAFT_REGO = D.ACFTABB

    WHERE AUDTCURI = 'C '.

    UNION

    SELECT AIRCRAFT_REGO AS "REGO",.

    'WARRANTY FAILURES' as "CRITERIA", he said.

    CNTWARNT AS 'COUNT '.

    OF UTEV0001 Z

    INNER JOIN (SELECT ACFTABB, COUNT (ACFTABB) AS CNTWARNT

    OF SIMLOG

    WHERE ACDFRCYC = S"

    AND GUARANTEED = 'Y '.

    ACFTABB GROUP

    order of ACFTABB) E

    ON Z.AIRCRAFT_REGO = E.ACFTABB

    WHERE AUDTCURI = 'C '.

    UNION

    SELECT AIRCRAFT_REGO AS "REGO",.

    "REFER CONTROLLER" as of "CRITERIA", he said.

    CNTCONT AS 'COUNT '.

    OF UTEV0001 V

    INNER JOIN (SELECT ACFTABB, COUNT (ACFTABB) AS CNTCONT

    OF SIMLOG

    WHERE ACDFRCYC = S"

    AND AFFECTED LIKE '% CONTROLLER '.

    ACFTABB GROUP

    order of ACFTABB) F

    ON V.AIRCRAFT_REGO = F.ACFTABB

    WHERE AUDTCURI = 'C')

    CRITERIA GROUP)

    Using this query, I get the following error "failed to parse the SQL query! "

    But when I use the query used to create the table here. It works perfectly fine.

    Could someone help me please.

    Hi Ajay,

    I would say it is your use of the key word 'number '. I would like to change it to "MY_COUNT" or something.

    I certainly expect

    SELECT THE NULL LINK,

    LABEL CRITERIA,

    DIGITAL VALUE

    fail because of the number keyword.

    Kofi

  • Need your help for writing query complex!

    Kindly give me your suggestion to write a query for some situation...

    suupose he is 10 in a circle Distributor. and also in each Distributor, there are 10 FOS under each Distributor... and to each FSO, there are also numbers retailers...

    Please suggest how to write the query, there look like... (possible may through XML...

    Distributor1, FOS1, rt_count, FOS2, rt_count, FOS3, rt_count
    Distributor2, FOS1, rt_count, FOS2, rt_count, FOS3, rt_count
    ...
    ...
    ...
    8751090151, 8751090147:10, 8751090148:25, 8751090149:11... .etc


    Here it is the data...

    date_crt dist_msisdn f os_msisdn rt_count
    26 MARCH 13 7399998263 7399998263 1
    26 MARCH 13 8751090151 8751090147 10
    26 MARCH 13 8751090151 8751090148 25
    26 MARCH 13 8751090151 8751090149 11
    26 MARCH 13 8751090151 8751090151 1
    26 MARCH 13 8751090151 8751090152 40
    26 MARCH 13 8751090151 8751090326 11
    26 MARCH 13 8751090151 8751090327 70
    26 MARCH 13 8751090151 8751090328 29
    26 MARCH 13 8751090151 8751090335 1
    26 MARCH 13 8751090151 9577162731 8
    26 MARCH 13 8751090151 9613381589 38
    26 MARCH 13 8751090151 9613381790 14
    26 MARCH 13 8751090151 9613381969 13
    26 MARCH 13 8751090151 9613385207 42
    26 MARCH 13 8751090151 9613385284 12
    26 MARCH 13 8751090151 9613386523 52
    26 MARCH 13 8751090151 9613389220 91
    26 MARCH 13 8751090151 9613530655 1

    Published by: user3558544 on 1 April 2013 05:36

    Published by: user3558544 on 1 April 2013 07:09

    You can validate the query in the exactly the way you are runnin it and the text of the error?

    The query with the name of the table that you post could look like this:

    Select dist_msisdn, rtrim (xmlagg (xmlelement (e, os_msisdn |': ' | rt_count |))) ",") stopped by os_msisdn |': ' | (rt_count) .extract ('/ / text()'), ',') combinatoria_b
    of LBA_ALERT
    Dist_msisdn group

  • hierarchical query complex

    Hello

    Please help for the scenario below
    col1 col2  val
    a      b     10
    b      c     30
    c      d      40
    in the dataset above I want to get the records as
    col1   col2   val
    a        c       30   ->maximum of ab and bc  which is 30
    a       d        40   ->maximum of ab,bc and cd  which is 40
    b       d       40    ->maximum of bc and cd   whcih is 40
    I tried the analytical function and hierarchical queries still I don't get an idea to achieve this, is it possible in a sql query or go for pl/sql block. Please suggest a solution

    Your description could be more verbose somehow.
    However, I'll try to guess

    with data (col1,col2,val) as (
    select 'a','b',10 from dual union all
    select 'b','c',30 from dual union all
    select 'c','d',40 from dual
    )
    , connects as (
    select
      connect_by_root(col1) r
    ,col1
    ,col2
    ,level lev
    , val -- could be something like
         -- ,max(val)over(partition by connect_by_root(col1)) val
        -- please provide some more testdata and more precise description on this
    from
    data
    connect by
    col1 = prior col2
    order by lev, col1
    )
    
    select
    r col1, col2, max(val)
    from connects
    where
    lev > 1
    group by r, col2
    order by r, col2
    
    COL1     COL2     MAX(VAL)
    a     c     30
    a     d     40
    b     d     40
    

    Published by: chris227 on 24.03.2013 05:05

  • Need help with a query complex for the production database

    Hello again,

    I need your help once again, for a query how to show me how long each stage of production is by order.
    See examples of data and what I expect.
    Thank you all for your help.

    We use Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Here the example data tables:
    CREATE      TABLE      TABLE_2
       
    (     "ORDER_NR"      VARCHAR2 (12)
    ,      "PRIORITY"      VARCHAR2 (2)
    ,      "WO_STEP"      VARCHAR2 (1)
    ,      "STEP_DATE"      DATE
    );
    
    CREATE      TABLE      TABLE_1
    (     "ORDER_NR"           VARCHAR2     (12) PRIMARY KEY
    ,      "PRIORITY"           VARCHAR2      (2)
    ,      "CREATE_DATE"      DATE
    ,     "ACT_STEP"          VARCHAR2     (2)
    ,     "STEP_DATE"          DATE
    ,     "EMPLOYEE"          VARCHAR2     (5)
    ,     "DESCRIPTION"     VARCHAR2     (20)
    );
    
    INSERT      INTO      TABLE_1      (ORDER_NR,               PRIORITY,      CREATE_DATE,                                                        ACT_STEP,     STEP_DATE,                                                            EMPLOYEE,     DESCRIPTION) 
                        VALUES           ('1KKA1T205634',     '12',          TO_DATE('10-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'),     'U',          TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'),     'W0010',     'CLEAN HOUSE');
    INSERT      INTO      TABLE_1      (ORDER_NR,               PRIORITY,     CREATE_DATE,                                                        ACT_STEP,     STEP_DATE,                                                            EMPLOYEE,     DESCRIPTION)
                        VALUES           ('1KKA1Z300612',     '12',          TO_DATE('08-FEB-13 14:00:00','DD-MON-RR HH24:MI:SS'),     'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'),     'K0052',     'REPAIR CAR');
    
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'A',          TO_DATE('12-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'K',          TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'K',          TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          '5',          TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'C',          TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'B',          TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'E',          TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'S',          TO_DATE('21-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'R',          TO_DATE('21-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1T205634',     '12',          'U',          TO_DATE('28-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'A',          TO_DATE('12-FEB-13 13:52:42','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 09:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'K',          TO_DATE('13-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 11:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'K',          TO_DATE('13-FEB-13 12:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          '5',          TO_DATE('13-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'C',          TO_DATE('14-FEB-13 08:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'B',          TO_DATE('14-FEB-13 10:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'E',          TO_DATE('18-FEB-13 13:00:00','DD-MON-RR HH24:MI:SS'));
    INSERT     INTO      TABLE_2      (ORDER_NR,               PRIORITY,     WO_STEP,     STEP_DATE)
                        VALUES           ('1KKA1Z300612',     '12',          'F',          TO_DATE('20-FEB-13 16:00:00','DD-MON-RR HH24:MI:SS'));
    COMMIT;
    And here's what I expect of my request:
    SYSDATE     28.Feb.13 14:00                                                                                     
                                                                                              
    ORDER_NR     PRIORITYCREATE_DATE     STATUS     STATUS_DATE     DESCRIPTION     AGE_1     AGE_2     WAITNG     STEP_A     STEP_B     STEP_C     STEP_5     STEP_K     STEP_E     STEP_F     STEP_S     STEP_R     
    1KKA1T205634     12     10.Feb.13 10:00     U     28.Feb.13 12:00     CLEAN HOUSE     18,083     8,833     2,125     0,833     4,125     0,083     0,750     0,208     2,125     0,666     0,042     7,125     
    1KKA1Z300612     12     08.Feb.13 14:00     F     20.Feb.13 16:00     REPAIR CAR     20,000     16,042     2,125     0,833     4,125     0,083     0,750     0,208     2,125     0,666          
    And now the explanation for the result of the query:
    The AGE_1 is the difference in days between the "CREATE_DATE" and if EXSIST L'ETAPE 'U' then STEP_DATE or if the STEP 'U' is not found in TABLE_2 then it should show the difference in days between the "CREATE_DATE' and the 'SYSDATE.
    The AGE_2 is the difference in days between the STEP "A" STEP_DATE and IF EXSIST L'ETAPE 'R' then STEP_DATE or if the STEP 'R' is not in TABLE_2 then it should show the difference in days between the "CREATE_DATE' and the 'SYSDATE.
    The EXPECTATION is the difference in days between CREATE_DATE and STEP 'A' STEP_DATE
    The following columns indicate the days, how long the ORDER_NR remains in these TIMES, if an ORDER_NR comes in the same STEP should be calculated together more than once.
    If the ORDER_NR jump a step, it should show a zero in the specific field.

    I hope that my explanation is good enough, my English skills are far from good.

    Thank you for all your help.

    Hosts Reinhard W.

    Solomon Yakobson says:
    Just add the amounts:

    In fact, you could edit all CASES:

    with t2 as (
                select  t.*,
                        lead(step_date) over(partition by order_nr order by step_date) next_step_date
                  from  table_2 t
               )
    select  t1.*,
            nvl(
                max(
                    case t2.wo_step
                      when 'U' then t2.step_date
                    end
                   ),
               sysdate
              ) - t1.create_date age_1,
            nvl(
                max(
                    case t2.wo_step
                      when 'R' then t2.step_date
                    end
                   ),
               sysdate
              ) - t1.create_date age_2,
            sum(
                case
                  when t2.wo_step in ('B','5') then t2.next_step_date - t2.step_date
                end
               ) step_b_5,
            sum(
                case t2.wo_step
                  when 'C' then t2.next_step_date - t2.step_date
                end
               ) step_c,
            sum(
                case t2.wo_step
                  when 'K' then t2.next_step_date - t2.step_date
                end
               ) step_k,
            sum(
                case t2.wo_step
                  when 'E' then t2.next_step_date - t2.step_date
                end
               ) step_e,
            sum(
                case t2.wo_step
                  when 'F' then t2.next_step_date - t2.step_date
                end
               ) step_f,
            sum(
                case t2.wo_step
                  when 'S' then t2.next_step_date - t2.step_date
                end
               ) step_s,
            sum(
                case t2.wo_step
                  when 'R' then t2.next_step_date - t2.step_date
                end
               ) step_r
      from  table_1 t1,
            t2
      where t2.order_nr = t1.order_nr
      group by t1.order_nr,
               t1.priority,
               t1.create_date,
               t1.act_step,
               t1.step_date,
               t1.employee,
               t1.description
    /
    
    ORDER_NR     PR CREATE_DA AC STEP_DATE EMPLO DESCRIPTION      AGE_1      AGE_2   STEP_B_5     STEP_C  STEP_K     STEP_E     STEP_F        STEP_S     STEP_R
    ------------ -- --------- -- --------- ----- ----------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
    1KKA1T205634 12 10-FEB-13 U  28-FEB-13 W0010 CLEAN HOUSE 18.0833333 10.9583333      4.875 .083333333 .208333333      2.125 .666666667 .041666667      7.125
    1KKA1Z300612 12 08-FEB-13 F  20-FEB-13 K0052 REPAIR CAR   44.252338  44.252338      4.875 .083333333 .208333333      2.125
    
    SQL>
    

    SY.

  • Need help to write a SQL query complex

    I have the source tabe as below

    -> SOURCE_TABLE
    NAME     CUST_ID     SVC_ST_DT     SVC_END_DT 
    TOM        1               31/08/2009      23/03/2011 
    DOCK       2               01/01/2004      31/05/2010 
    HARRY      3               28/02/2007      31/12/2009 
    I want to load as target table below
    -> TARGET_TABLE
    NAME     CUST_ID                     SVC_ST_DT      SVC_END_DT 
    TOM      1           31/08/2009      31/12/2009 
    TOM      1           01/01/2010      31/12/2010 
    TOM      1           01/01/2011      23/03/2011 
    DOCK      2           01/01/2004      31/12/2004 
    DOCK      2           01/01/2005      31/12/2005 
    DOCK      2           01/01/2006      31/12/2006 
    DOCK      2           01/01/2007      31/12/2007 
    DOCK      2           01/01/2008      31/12/2008 
    DOCK      2           01/01/2009      31/12/2009 
    DOCK      2           01/01/2010      31/05/2010 
    HARRY      3           28/02/2007      31/12/2007 
    HARRY      3           01/01/2008      31/12/2008 
    HARRY      3           01/01/2009      31/12/2009 
    Is it possible to write a SQL query that returns the data in the same way above the target table.

    Published by: AChatterjee on April 30, 2012 07:14

    Published by: AChatterjee on April 30, 2012 07:14

    Or like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  with t as (select 'TOM' as NAME, 1 as CUST_ID, date '2009-08-31' as SVC_ST_DT, date '2011-03-23' as SVC_END_DT from dual union all
      2             select 'DOCK', 2, date '2004-01-01', date '2010-05-31' from dual union all
      3             select 'HARRY', 3, date '2007-02-28', date '2009-12-31' from dual)
      4  --
      5  -- end of test data
      6  --
      7  select name, cust_id, svc_st_dt, svc_end_dt
      8  from (
      9        select name
     10              ,cust_id
     11              ,greatest(svc_st_dt, add_months(trunc(svc_st_dt,'YYYY'),yr*12)) as svc_st_dt
     12              ,least(svc_end_dt, add_months(trunc(svc_st_dt,'YYYY'),(yr+1)*12)-1) as svc_end_dt
     13        from t
     14             cross join (select rownum-1 as yr
     15                         from   dual
     16                         connect by rownum <= (select extract(year from max(svc_end_dt)) - extract(year from min(svc_st_dt)) + 1 from t)
     17                        )
     18       )
     19  where svc_st_dt <= svc_end_dt
     20* order by 2, 3
    SQL> /
    
    NAME     CUST_ID SVC_ST_DT            SVC_END_DT
    ----- ---------- -------------------- --------------------
    TOM            1 31-AUG-2009 00:00:00 31-DEC-2009 00:00:00
    TOM            1 01-JAN-2010 00:00:00 31-DEC-2010 00:00:00
    TOM            1 01-JAN-2011 00:00:00 23-MAR-2011 00:00:00
    DOCK           2 01-JAN-2004 00:00:00 31-DEC-2004 00:00:00
    DOCK           2 01-JAN-2005 00:00:00 31-DEC-2005 00:00:00
    DOCK           2 01-JAN-2006 00:00:00 31-DEC-2006 00:00:00
    DOCK           2 01-JAN-2007 00:00:00 31-DEC-2007 00:00:00
    DOCK           2 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    DOCK           2 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    DOCK           2 01-JAN-2010 00:00:00 31-MAY-2010 00:00:00
    HARRY          3 28-FEB-2007 00:00:00 31-DEC-2007 00:00:00
    HARRY          3 01-JAN-2008 00:00:00 31-DEC-2008 00:00:00
    HARRY          3 01-JAN-2009 00:00:00 31-DEC-2009 00:00:00
    
    13 rows selected.
    
  • Need help with PL/SQL query complex

    I need help with a query that need access to data from 3 tables. That's what I did

    I created 3 tables

    CREATE TABLE post_table
    (
    post_id varchar (20),
    datepost DATE,
    KEY (post_id) elementary SCHOOL
    ) ;

    CREATE TABLE topic
    (
    TOPIC_ID varchar (20),
    name varchar (20),
    PRIMARY KEY (topic_id)
    );

    CREATE TABLE blogpost_table
    (
    TOPIC_ID varchar (20),
    post_id varchar (20),
    PRIMARY KEY (topic_id, post_id);
    FOREIGN KEY (topic_id) REFERENCES topic (topic_id) ON DELETE CASCADE,
    FOREIGN KEY (post_id) REFERENCES post_table (post_id) ON DELETE CASCADE
    );


    Now, I inserted a few values in these tables as

    INSERT INTO post_table VALUES ('p1', to_date ('2009-09-14 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p2', to_date ('2009-07-18 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p3', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p4', to_date ('2009-03-11 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p5', to_date ('2009-07-13 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p6', to_date ('2009-06-12 18:00 "," MM/DD/YYYY mi:ss'));))
    INSERT INTO post_table VALUES ('p7', to_date ('2009-07-11 18:00 "," MM/DD/YYYY mi:ss'));))

    INSERT INTO VALUES subject ("t1", "baseball");
    INSERT INTO category VALUES ('t2', 'football');

    INSERT INTO blogpost_table VALUES ("t1", "p1");
    INSERT INTO blogpost_table VALUES ('t1', 'p3');
    INSERT INTO blogpost_table VALUES ("t1", "p4");
    INSERT INTO blogpost_table VALUES ('t1', 'p5');
    INSERT INTO blogpost_table VALUES ('t2', 'p2');
    INSERT INTO blogpost_table VALUES ('t2', 'p6');
    INSERT INTO blogpost_table VALUES ("t2", "p7");


    I'm launching SQL queries on the table in this topic.

    I want to write a SQL query that returns me the name of a topic (s) and the number of blog_post (s) associated with the topic in descending order of the number of blog posts created in July.

    Can someone please help me to write this query?

    Thank you

    Published by: user11994430 on October 9, 2009 07:24

    Thanks for the test of the configuration!

    SQL>SELECT   t.NAME, COUNT(*)
      2      FROM topic t, blogpost_table b, post_table p
      3     WHERE b.topic_id = t.topic_id
      4       AND p.post_id = b.post_id
      5       AND p.datepost >= DATE '2009-07-01'
      6       AND p.datepost < DATE '2009-08-01'
      7  GROUP BY t.NAME
      8  ORDER BY COUNT(*) desc;
    
    NAME                   COUNT(*)
    -------------------- ----------
    baseball                      2
    soccer                        2
    

    HTH, Urs

  • Strange ROWNUM result on query complex using separate results

    We have a very complicated query that is a combination of implicit and explicit joins on more than 10 tables in the database. Due to performance issues and timeout if we let him return the entire result set, I'm limiting it to a number using rownum.

    Initially, we were using a "select * of (select distinct * insert here * order of main by id request) where rownum < = 300 ', but work stopped when a new piece of research has been implemented that makes the whole result set then cut accepting up to 300 results for 5 minutes, which is the maximum of our web server can define for a timeout.

    So I tried to change it simply to "select distinct * insert here the main query * and rownum < = 300. This is for a reason any returns only one record. If I add THAT ROWNUM to the list of displayed values it displays 300 lines of exactly the same values with different rownums, who then likely get collapsed down by the distinct in the single record that I see.

    Is there a better way to do it? We can't simply not the complete set of results in a subquery to whittle down, but try to whittle down to the main request gives weird results.

    A better approach would be to improve the performance of the main query. On the one hand, do come back less (or not) duplicate lines would probably improve the performance considerably, because he's back at least 300 copies of certain lines. Making a DIFFERENT one on a large number of lines can be a problem in itself huge performance.

  • Need help with a query complex

    ID Col1 Col2 COL3 COL4 VAL
    1col1_1col2_1col3_1col4_1val1
    1col1_1col2_1col3_1*val2
    1col1_1col2_1**val3
    1col1_1***Val4
    1****Val5

    I want to get the result.

    Col1, col2, col3, col4 will be entered and I need to find the Val by matching the Col1, col2, col3 col4.

    IF there is no match for any column, then it should consider it as *.

    So basically for any value of Col1, col2, col3, col4, it should return Val.

    Example - he must return val1 for col1_1, col2_1, col3_1, col4_1

    and val5 for col1_11, col2_11, col3_11 and col4_11 have no match for all 4 columns here.

    How to write a simplified in this case request? any help is really appreciated.

    SQL > with t as)
    2. Select val,
    3 dense_rank() on)
    4 order of col1 case when ' *' then 0 end of another 1 +.
    5 case col2 where ' *' then 0 end of another 1 +.
    6 case col3 where ' *' then 0 end of another 1 +.
    7 case col4 when ' *' 0 then 1 other side desc
    8                                      ) rnk
    9 of tbl
    10 where col1 in ('col1_1','* ')
    11 and col2 in ('col2_1','* ')
    12 and col3 in ('col3_1','* ')
    13 and col4 in ('col4_1','* ')
    14            )
    15 select val
    16 t
    where the 17 rnk = 1
    18.

    VAL
    ----
    val1

    SQL > with t as)
    2. Select val,
    3 dense_rank() on)
    4 order of col1 case when ' *' then 0 end of another 1 +.
    5 case col2 where ' *' then 0 end of another 1 +.
    6 case col3 where ' *' then 0 end of another 1 +.
    7 case col4 when ' *' 0 then 1 other side desc
    8                                      ) rnk
    9 of tbl
    10 where col1 in ('col1_11','* ')
    11 and col2 in ('col2_11','* ')
    12 and col3 in ('col3_11','* ')
    13 and col4 in ('col4_11','* ')
    14            )
    15 select val
    16 t
    where the 17 rnk = 1
    18.

    VAL
    ----
    Val5

    SQL >

    SY.

  • Need to query complex

    Hi Experts,

    I have a table where for each change in the employee from the start date and end date is maintained as below
    WITH TEST_TAB
       AS ( 
       SELECT 'ABC' NAME, 2 ID, TO_DATE('1-JAN-2011') stdate, TO_DATE('1-FEB-2011') endate,     12345789 seqno, 'X1' TYPE, 'S' FLAG, 3 C1, 'ZC' C2, 'X' C3, 'N' C4 FROM DUAL
       UNION ALL
       SELECT 'ABC', 2, TO_DATE('1-FEB-2011'), TO_DATE('1-NOV-2011'), 12345789, 'X2', 'S', 3, 'ZC', 'X', 'N' FROM DUAL
       UNION ALL
       SELECT 'ABC', 2, TO_DATE('1-NOV-2011'), TO_DATE('1-JAN-2299'), 12345789, 'X2', 'S', 0, 'Z4', 'S', 'N' FROM DUAL -- NOTICE THIS IS THE ROW WITH LATEST VALUES
         )
       SELECT * FROM TEST_TAB
    NAM         ID STDATE    ENDATE         SEQNO TY F         C1 C2 C C
    --- ---------- --------- --------- ---------- -- - ---------- -- - -
    ABC          2 01-JAN-11 01-FEB-11   12345789 X1 S          3 ZC X N
    ABC          2 01-FEB-11 01-NOV-11   12345789 X2 S          3 ZC X N
    ABC          2 01-NOV-11 01-JAN-99   12345789 X2 S          0 Z4 S N 
    I need data wise months of each employee in the below format
    EFF_DATE     Name     SeqNo          Type     Flag     C1     C2     C3     C4
    --------     ----     --------     ----     ----     ---     ---     ---     ---
    1-JAN-2011     ABC     12345789     X1     S     3     ZC     X     N
    1-FEB-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-MAR-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-APR-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-MAY-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-JUN-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-JUL-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-AUG-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-SEP-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-OCT-2011     ABC     12345789     X2     S     3     ZC     X     N
    1-NOV-2011     ABC     12345789     X2     S     0     Z4     S     N
    Thanks in advance,
    Concerning

    You can try using:

    WITH TEST_TAB AS (SELECT 'ABC' NAME, 2 ID, TO_DATE('01/01/2011', 'dd/mm/yyyy') stdate, TO_DATE('01/02/2011', 'dd/mm/yyyy') endate,  12345789 seqno, 'X1' TYPE, 'S' FLAG, 3 C1, 'ZC' C2, 'X' C3, 'N' C4 FROM DUAL
                      UNION ALL
                      SELECT 'ABC', 2, TO_DATE('01/02/2011', 'dd/mm/yyyy'), TO_DATE('01/11/2011', 'dd/mm/yyyy'), 12345789, 'X2', 'S', 3, 'ZC', 'X', 'N' FROM DUAL
                      UNION ALL
                      SELECT 'ABC', 2, TO_DATE('01/11/2011', 'dd/mm/yyyy'), TO_DATE('01/01/2299', 'dd/mm/yyyy'), 12345789, 'X2', 'S', 0, 'Z4', 'S', 'N' FROM DUAL -- NOTICE THIS IS THE ROW WITH LATEST VALUES
                      UNION ALL
                      SELECT 'DEF', 2, TO_DATE('10/02/2011', 'dd/mm/yyyy'), TO_DATE('26/03/2011', 'dd/mm/yyyy'), 12345789, 'X2', 'S', 3, 'ZC', 'X', 'N' FROM DUAL),
           months as (select add_months(trunc(min_stdate, 'mm'), level -1) mon
                      from   (select min(stdate) min_stdate, max(stdate) max_stdate
                              from   test_tab)
                      connect by level <= months_between(max_stdate, min_stdate) + 1)
    select greatest(tt.stdate, mth.mon) eff_date,
           tt.name,
           seqno,
           type,
           flag,
           c1,
           c2,
           c3,
           c4
    from   months mth
           join test_tab tt on (trunc(tt.stdate, 'mm') <= mth.mon and tt.endate > mth.mon)
    order by name, mth.mon;
    
    EFF_DATE   NAME      SEQNO TYPE FLAG         C1 C2 C3 C4
    ---------- ---- ---------- ---- ---- ---------- -- -- --
    01/01/2011 ABC    12345789 X1   S             3 ZC X  N
    01/02/2011 ABC    12345789 X2   S             3 ZC X  N
    01/03/2011 ABC    12345789 X2   S             3 ZC X  N
    01/04/2011 ABC    12345789 X2   S             3 ZC X  N
    01/05/2011 ABC    12345789 X2   S             3 ZC X  N
    01/06/2011 ABC    12345789 X2   S             3 ZC X  N
    01/07/2011 ABC    12345789 X2   S             3 ZC X  N
    01/08/2011 ABC    12345789 X2   S             3 ZC X  N
    01/09/2011 ABC    12345789 X2   S             3 ZC X  N
    01/10/2011 ABC    12345789 X2   S             3 ZC X  N
    01/11/2011 ABC    12345789 X2   S             0 Z4 S  N
    10/02/2011 DEF    12345789 X2   S             3 ZC X  N
    01/03/2011 DEF    12345789 X2   S             3 ZC X  N 
    
  • Strange question QoQ when you query a Solr collection

    Hello, everyone.

    I have a query request number that left me speechless.  Maybe I'm missing just something very simple, but it made me really confuzzed.

    I have a collection of Solr that indexes a few tables in an Oracle database.  Let's call it 'Hannah', for this discussion.

    I wrote a query complex semi of tables, where the CFINDEX uses to index the data.  It works very well.

    I created the Solr collection in the CFAdmin CF9 and uses to index with the following:

    < cfindex action = "Refresh" collection = key 'Hannah' = 'QUESTION_ID' type = "custom" title = "QUESTION_TITLE" query = "search_questions" body = "QUESTION_TX, QUESTION_TITLE, CATEGORY_NM, TAG_NM, ANSWER_TITLE, ANSWER_TX.

    CUSTOM1 custom2 "QUESTION_STATUS" = "TAG_NM" custom3 = = "QUESTION_STATUS" custom4 = category "QUESTION_TYPE" = "CATEGORY_NM" >

    Then I do a CFSEARCH and name it "hd_questions".  Once again, so far, everything's fine, no problem.

    If I do a CFDUMP of the 'hd_questions', one of the columns is the KEY (which is QUESTION_ID in the database).  If I've got CFOUTPUT collection, KEY is there.

    If I t/t the CFSEARCH to the custom3 SELECT collection and use, result, summary, context, hd_questions key, I get an error message that

    Meeting "key. Select incorrect, incorrect list select the column

    .. then he gives the line number of the page that produced the error, and

    < cfquery dbtype = "query" name = "hd_results" >

    Am I missing something simple here?  KEY is in the collection, I can see it in CFDUMP, I can see in CFOUTPUT.  But if I ask the collection and try to pick the KEY, there is an error.

    Any thoughts/ideas?

    Thank you

    ^_^

    Key is a reserved word in Coldfusion, cannot be used directly in a QoQ without dropping it.  Try wrapping it in [] instead, i.e. [key]

    It can also help to give it an alias too, for example SELECT [key] AS the Council

    See the list of reserved here words: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec173d0-7f ff.html and t/t guide using here reserved words: http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0e4fd-7ff0.html #WSc3ff6d0ea77859461172e0811cbec22c24-7008

Maybe you are looking for

  • How to remove predictive text bar?

    Hi all I've just updated to iOS10 and when texting etc. the predictive text bar is above the keyboard. On versions previous IOS you could easily hide this sliding downwards, however this ability has been removed. Am I stuck with that boring bar forev

  • HPDM 4.7 / HP T520: Error Code 34603008 / Imaging with HPDM 4.7

    Hi all I have a problem with a T520 HP with HP Device Manager 4.7 SP4 running on the server 2012R2, trying to capture an image from a T520 HP ThinPro 6, version of the 4.7.3671.25484 agent. Capture the profile and the settings worked. Server and devi

  • Load the Apple Watch

    Hello: I just bought a Apple Watch.  I have it plugged into the port of wall and I was curious the way whose time it takes to load completely before being used? Thanks in advance.

  • My HPOfficejet j4680 wireless all-in-one printer error message says its offline

    I have and have used several times my HPOfficejet j4680 wireless all-in-One printer to print. But this past week it will not print. I keep getting error messages that says that it is offline or turned off. But the green power light is on. The blue wi

  • (Redirected) Need to talk to corporate officers of complaint about the guarantee

    Hello   I called him today and was not helped. I had an agent to disconnect the line on me. I have pointed out the problems with my computer. This computer is an exchange in the previous year. I talked to a person who called the Manager himself, he w