Query question

I'm trying to take the original code and do better.  Here is what was originally:
They would make 3 calls (I try to combine the 3 box instructions in section 2 below

SELECT boxserial,

substr (boxserial, 2, 1) prod_line.

PN,

model_number,

model_year

As AS Sum (Qty)

OF SHIPPING_LABEL_HISTORY

WHERE the BOX_DATE_TIME BETWEEN to_date (April 16, 2014 00:00:00 ',' dd-mm-yyyy hh24:mi:ss') AND to_date (April 16, 2014 02:59:59 ',' yyyy-mm-dd hh24:mi:ss')

AND slh.qty > 0

GROUP BY boxserial, substr (boxserial, 2, 1), PN, model_number, model_year

ORDER BY substr (slh.boxserial, 2, 1)

This is what I have so far but I am not clear how to add the slh.qty > 0:

SELECT slh. BOXSERIAL, slh. KCST_PN, slh. MODEL_NUMBER, slh. MODEL_YEAR, sm. DESCRIPTION ACE LINE,

CASE WHEN BOX_DATE_TIME BETWEEN TO_DATE (April 16, 2014 00:00:00 ', 'Hh24:mi:ss dd-mm-YYYY') AND TO_DATE (April 16, 2014 02:59:59 ', 'Dd-mm-YYYY Hh24:mi:ss')

THEN the SUM (slh. QTY)

0 OTHERWISE

END as BoxQty,

CASE WHEN REBOX_DATE_TIME BETWEEN the TO_DATE('04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss') AND the TO_DATE (April 16, 2014 02:59:59 ',' YYYY-mm-dd hh24:mi:ss')

THEN the SUM (slh. QTY)

0 OTHERWISE

END as ReboxQty,

CASE WHEN UNBOX_DATE_TIME BETWEEN the TO_DATE('04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss') AND the TO_DATE (April 16, 2014 02:59:59 ',' YYYY-mm-dd hh24:mi:ss')

THEN the SUM (slh. QTY)

0 OTHERWISE

END AS UnboxQty

OF SHIPPING_LABEL_HISTORY slh

BLP LEFT JOIN PROD_LAST_BOX_SERIAL ON SUBSTR(slh.) BOXSERIAL, 2, 1) = BLP. LINE

LEFT JOIN ECU_STEP_MACHINE sm ON BLP. STEP_MACHINE = sm. STEP_MACHINE

WHERE the BOX_DATE_TIME BETWEEN TO_DATE (April 16, 2014 00:00:00 ', 'Hh24:mi:ss dd-mm-YYYY') AND TO_DATE (April 16, 2014 02:59:59 ', 'Dd-mm-YYYY Hh24:mi:ss')

OR REBOX_DATE_TIME BETWEEN TO_DATE (April 16, 2014 00:00:00 ', 'Hh24:mi:ss dd-mm-YYYY') AND TO_DATE (April 16, 2014 02:59:59 ', 'Dd-mm-YYYY Hh24:mi:ss')

OR UNBOX_DATE_TIME BETWEEN TO_DATE (April 16, 2014 00:00:00 ', 'Hh24:mi:ss dd-mm-YYYY') AND TO_DATE (April 16, 2014 02:59:59 ', 'Dd-mm-YYYY Hh24:mi:ss')

GROUP BY slh. BOXSERIAL, slh. KCST_PN, slh. MODEL_NUMBER, slh. MODEL_YEAR, sm. DESCRIPTION, BOX_DATE_TIME, REBOX_DATE_TIME, UNBOX_DATE_TIME

ORDER BY substr (slh.boxserial, 2, 1);

Any help is greatly appreciated.

Maybe like this?

  SELECT slh.boxserial, slh.kcst_pn, slh.model_number, slh.model_year
       , sm.description AS line
       , SUM (CASE
                 WHEN box_date_time BETWEEN TO_DATE ( '04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss') AND TO_DATE ( '04-16-2014 02:59:59', 'mm-dd-YYYY hh24:mi:ss')
                 THEN slh.qty
                 ELSE 0
             END) AS boxqty
       , SUM (CASE
                 WHEN rebox_date_time BETWEEN TO_DATE ( '04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss') AND TO_DATE ( '04-16-2014 02:59:59', 'mm-dd-YYYY hh24:mi:ss')
                 THEN slh.qty
                 ELSE 0
             END) AS reboxqty
       , SUM (CASE
                 WHEN unbox_date_time BETWEEN TO_DATE ( '04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss') AND TO_DATE ( '04-16-2014 02:59:59', 'mm-dd-YYYY hh24:mi:ss')
                 THEN slh.qty
                 ELSE 0
             END) AS unboxqty
    FROM shipping_label_history slh
         LEFT JOIN prod_last_box_serial plbs
            ON SUBSTR ( slh.boxserial, 2, 1) = plbs.line
         LEFT JOIN ecu_step_machine sm
            ON plbs.step_machine = sm.step_machine
   WHERE box_date_time BETWEEN TO_DATE ( '04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss')
                           AND TO_DATE ( '04-16-2014 02:59:59', 'mm-dd-YYYY hh24:mi:ss')
      OR rebox_date_time BETWEEN TO_DATE ( '04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss')
                             AND TO_DATE ( '04-16-2014 02:59:59', 'mm-dd-YYYY hh24:mi:ss')
      OR unbox_date_time BETWEEN TO_DATE ( '04-16-2014 00:00:00', 'mm-dd-YYYY hh24:mi:ss')
                             AND TO_DATE ( '04-16-2014 02:59:59', 'mm-dd-YYYY hh24:mi:ss')
GROUP BY slh.boxserial, slh.kcst_pn, slh.model_number, slh.model_year, sm.description, box_date_time, rebox_date_time, unbox_date_time
ORDER BY SUBSTR ( slh.boxserial, 2, 1);

It would be nice if you could post some examples of data such as create table and insert.

I could not test this.

Kind regards.

Alberto

Tags: Database

Similar Questions

  • Progressive, Question on the fields of dynamic/DocID/Query Question of profiling

    This may seem like a newb question but someone has a logical division of the BOM designation DocID?

    In the course, we are responsible to use DocID = 1 and DocID = 2, but when/why would you use DocID = 3 or higher?

    Any help would be greatly appreciated with the portion of dynamic fields/query string of the progressive profiling course.

    Thank you.

    The DocID is a complete example. You can actually assign the query string to be what you want. I recently use cmpID for the campaign ID, where I spent to map identity of the campaign and then sent the URL to redirect dynamically the campaign ID field. In my case, we worked with 10 different docs or goods, so we had to actually 10 unique codes. In this case we would have, for example cmpID = 483h76d; cmpID = 9j872hd, etc, etc. If you want to learn more about how you can use the query string values, see this post: how Progressive E10 profiling using the component of cloud - scroll down to step 6 and you'll see how to set up dynamic rules using query strings.

  • XML PIVOT QUERY QUESTIONS

    I'm new to PIVOT queries.  I was making reference to the discussion that follows, but ran into a problem.  https://forums.Oracle.com/message/9393302

    When I added the XML to format data, I started to have NULL values rather than what I was looking for.

    WITH (AS PIVOT_DATA)

    SELECT * FROM)

    SELECT THE REGION, FCST_PERIOD, PRIME_PART, FINAL_FORECAST

    OF XYZ WHERE FCST_PERIOD > = last_day (trunc (sysdate)) + 1 and FCST_PERIOD < = last_day (add_months(sysdate,12)) AND PRIME_PART IN ('BLAH')

    )

    PIVOT XML (SUM (FINAL_FORECAST) FOR FCST_PERIOD IN (SELECT DISTINCT FCST_PERIOD OF XYZ))

    )

    SELECT PRIME_PART, REGION,

    EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[1]/COLUMN[2]') FCST_PERIOD1,

    EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[2]/COLUMN[2]') FCST_PERIOD2,

    EXTRACTVALUE(FCST_PERIOD_XML,'/PIVOTSET/ITEM[3]/COLUMN[2]') FCST_PERIOD3

    OF PIVOT_DATA;

    RESULTS IN:

    PRIME_PARTREGIONFCST_PERIOD1FCST_PERIOD2FCST_PERIOD3
    BLAMIDWEST(NULL)(NULL)(NULL)
    BLAWEST-NV(NULL)(NULL)(NULL)
    BLASOUTH-EAST(NULL)(NULL)(NULL)
    BLAWEST-CA(NULL)(NULL)(NULL)
    BLASOUTHWEST(NULL)(NULL)(NULL)
    BLAEAST(NULL)(NULL)(NULL)

    The second part of my question is how would I do a group when you use a pivot query.  When I finished, I've has several parts and would like to group by REGION.

    Thank you!

    Names of elements and attributes in XML are case-sensitive.

    Try with:

    EXTRACTVALUE (FCST_PERIOD_XML, ' / PivotSet/item [1] /column [2]') FCST_PERIOD1

    There is also a good chance that EXTRACTVALUE is frowned upon in your version. Instead, use XMLQuery or XMLTable.

    That being said, using XML PIVOT just to grind it later into a number known columns is pretty useless.

    The same can be achieved much more efficiently with regular PIVOT operator (and if necessary analytical function).

    Post some examples of data in the table of your database and your final result expected to get useful assistance.

  • Query does not work on my iPad (was: media query question)

    I am a site for mobile/tablet/Office of coding and while my office and the iphone respond to the CSS, my ipad does not work. The changes that I do take the tablet in dreamweaver, but when they go live the ipad does not. Of course, my media query must be incorrect, but I can't understand the question. Any help is very appreciated.

    http://gbetza.mydomain.com/WebService2/test/KathrynFee/2014/profile.html

    Thank you.

    Yes.  It is inevitable because smart phones are getting bigger while tablets are smaller & more.  He's always going to be some crossover.   Think of it this way, when a Tablet is behaving as a mobile device, he takes over the mobile network.  When the shelf behaves more like a desktop computer, you need the layout of office.

    Similarly, a great smartphone in landscape mode is likely to resemble the layout of your tablet.

    See the FluidGrid example below:

    http://ALT-Web.com/FluidGrid/Fluid2.html

    Office = 4-col layout

    Tablet = 2-col layout

    Mobile = 1-col layout

    For purposes of illustration, I added a thick border of gold at the disposal of the Tablet only.

    / * Tablet Layout: 481px to 768px. Inherits the styles of: Mobile layout. */

    @media only screen and (min-width: 481px) and (max-width: 768px) {}

    .gridContainer {width: 92%; border: 16px solid gold}

    }

    Nancy O.

  • BI Publisher data model / query question

    Hello

    I'm designing a report of BI Publisher where I need to show negative numbers in red. I'm perfectly fine with the help of the conditional formatting to do this (just using the default value is conditional formatting in the add-in in MS Word, that generates code like this:)

    <? If: number(Cost_-_MTD) < 0? > <? attribute@InContext:color;' Red '? > <? end if? >

    BUT...

    I have columns returning who sometimes have a NULL value in them, and when they have the value NULL, it causes the foregoing to the pipe upwards. So I thought, 'I'll just add IfNull() in queries defined in the model data, and who will take care of the problem... "

    that works - a little. Now, my problem is if I have to go back and change the query for some reason, I get an error "query cannot be parsed, please modify the query manually. I really don't want to do that, I wish that other developers do NOT have to manually change the queries.

    So my question is - is it possible to add in the IfNull() directly in the query designer, so it should not be changed manually from that moment?

    p.s. using IfNull OBIEE server as our data source.

    Thanks in advance,
    Scott

    I don't think there is a way to add the ifnull condition in the query designer. So, you will need to manually change the query...

    In your model so you can add additional control like this:
    <0?>...

    Thank you!

    Published by: BIPuser on Sep 17, 2010 09:20

  • SQL Query Question campaign

    I have a table that has at least 40 values that I need to use as variables in CCA. My question is. If I write the query as follows:

    SELECT AS $Var1 of the value1, value2 AS $Var2, ETC... I do for 40 fields. Would it work if I just do a query where I

    SELECT * FROM DBNAME WHERE CALLER = "$ANI."

    and then simply use the column as variables names?

    If you need 40 variables in your campaign to act on and use in logic, then you must list and assign all 40 as your first example.

  • PTC connector query questions

    I develop a connector and had some questions about the presentation of the petition. I tried to read the documentation and help, but saw no reference to these issues. I know that some of these things may not still have public API, but any help would be appreciated.

    (1) is it possible to disable the entry blank for a ComboBox and set one of the values? I am referring to when you click on the button '+' on a query and selecting a comboBox field. I tried the 'enableEmptyEntry' attribute but could do not seem to work.

    (2) is there a way to prevent several lines for the same domain? I'm trying to match a web interface that allows values separated by commas in certain areas and not others. Trying to decipher the intent of the user if they use multiple lines for the same field becomes confused.

    (3) is there a way to disable 'Match All' or 'match any '?

    Thank you

    After further review, the removal of the empty the box entry drop-down list on the query page is not possible.

    One feature that we've added in the last release to support the case where the user needs to find records with a null or empty value for this combobox field. For example, finding bugs without test status. We have generic for all drop-down list boxes.

    The 'enableEmptyEntry' attribute is intended to work with the attribute "emptyEntryValue" as a pair. The user can do something like this in def.xml:
    enableEmptyEntry = 'true '.
    "emptyEntryValue =""
    Our framework poster in the drop-down list instead of empty or the default value .

    We recorded a feature request for this for a future version. Currently, writer connector is not a way to customize our application page, including the MatchAll, MatchAny option.

  • where query question

    Ive HI you try to run a query that uses an apex link var to add a where clause per month on a date field

    Select print_month, to_char (PRINT_MONTH, 'Month') of print_schedule

    This query returns

    "PRINT_MONTH", "M".

    ' 01/12/2015', 'December '.

    ' 01/12/2015', 'December '.

    ' 01/10/2015', 'October '.

    ' 01/10/2015', 'October '.

    ' 01/08/2015', 'August '.

    Now then I try this query

    Select print_month, to_char (trunc (PRINT_MONTH), 'Month') of print_schedule where to_char (trunc (PRINT_MONTH), 'Month') = 'December '.

    I have some found data.

    The print_month field is a date column.

    Oracle 12 c

    HI, I fixed that I noticed when I opened the csv file in a text editor so that I could paste the result in the post that there are spaces at the end of month names string, so I added in the trunk as I thought that would fix it, but it didn't so I added now in a PLATE and it works

    Select print_month, RTRIM (to_char (trunc (PRINT_MONTH), 'Month')) from print_schedule where RTRIM (to_char (trunc (PRINT_MONTH), 'Month')) = "December".

    So I have some might explain why this is the case, why should I cut the tank a date version?

    Measure out why add white space on the end?

  • SQL Query Question of multiple criteria

    Hi all

    I currently have a query that provides me with a count for a criterion (C), but I also want to include the number of criteria (A) and (E) within the same query if possible. Here's what I have:

    SELECT B.MDA_LEV3_DEPT_NAME AS "TEU Area", AS COUNT (Z.MDA_EPAF_STATUS) PROJECT

    PS_MDA_EPAF_RQST Z, PS_MDA_EMPLOYEES B, PS_MDA_EPAF_WFXREF T

    WHERE MDA_EPAF_STATUS = 'C '.

    AND T.ORIGINATORID = Z.USERID

    AND Z.USERID = B.EMPLID

    AND Z.TRANSACTION_NBR = T.TRANSACTION_NBR

    B.MDA_LEV3_DEPT_NAME GROUP

    ORDER BY B.MDA_LEV3_DEPT_NAME;

    Which produces:

    Area of EVPProject Manager
    Office of VP University Affairs Sr5
    Cancer medicine30
    Cancer medicine - research49
    Cancer Prev & Pop science3
    Cancer Prev & science-Res Pop1
    Diagnostic Imaging2
    Information services16
    Internal medicine5
    Pathology/laboratory medicine2
    Pathology/laboratory medicine - Resch1
    Pediatrics13
    Provost and EVP departments1
    Radio-Oncology26
    Radio-Oncology - search2
    Regulatory Affairs1
    Surgery4
    Vice Provost research clinical1
    Vice Provost Science42

    But I want to understand (A) approved County and (E) which is pending County so it would look like:

    Area of EVPProject ManagerCounty approvedCounty pending
    Office of VP University Affairs Sr5
    Cancer medicine30
    Cancer medicine - research49
    Cancer Prev & Pop science3
    Cancer Prev & science-Res Pop1
    Diagnostic Imaging2
    Information services16
    Internal medicine5
    Pathology/laboratory medicine2
    Pathology/laboratory medicine - Resch1
    Pediatrics13
    Provost and EVP departments1
    Radio-Oncology26
    Radio-Oncology - search2
    Regulatory Affairs1
    Surgery4
    Vice Provost research clinical1
    Vice Provost Science42

    Maybe (guessing)

    SELECT B.MDA_LEV3_DEPT_NAME AS 'TEU Area. "

    PROJECT COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'C' THEN 1 END) AS,

    COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'A' THEN 1 END) APPROVED,

    AS COUNT(CASE Z.MDA_EPAF_STATUS WHEN 'P' THEN 1 END) PENDING

    OF PS_MDA_EPAF_RQST Z.

    B PS_MDA_EMPLOYEES,

    PS_MDA_EPAF_WFXREF T

    WHERE MDA_EPAF_STATUS ('C', 'A', 'P')

    AND T.ORIGINATORID = Z.USERID

    AND Z.USERID = B.EMPLID

    AND Z.TRANSACTION_NBR = T.TRANSACTION_NBR

    B.MDA_LEV3_DEPT_NAME GROUP

    ORDER BY B.MDA_LEV3_DEPT_NAME

    Concerning

    Etbin

  • SQL query question

    I have a table named Test, data inserted as below

    col1 Val
    There3
    x1
    z2

    We write a query to output below:

    col1 Val
    x1
    There2
    z3

    Please suggest the best way to reach above result.

    It is not clear what you're trying to do, but you can use something like:

    Select col1,

    ROW_NUMBER() (any order of col1) val

    of the test

    /

    For example:

    with the trial as)

    Select 'x' col1, 3 val union double all the

    Select 'y', 2 double Union all

    Select 'z', 1 double

    )

    Select col1,

    ROW_NUMBER() (any order of col1) val

    of the test

    /

    C VAL
    - ----------
    x          1
    y          2
    z          3

    SQL >

    SY.

  • Hierarchical query question

    Hi all

    I'm working on the database version (please avoid comments like "you should upgrade to a newer version," it's not me):

    Select * from version of v$.

    BANNER

    ----------------------------------------------------------------

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64 bit Production

    PL/SQL Release 9.2.0.8.0 - Production

    CORE Production 9.2.0.8.0

    AMT for HP - UX: 9.2.0.8.0 - Production Version

    NLSRTL Version 9.2.0.8.0 - Production

    I have the following hierarchical data:

    with mydata (emp_id, mgr_id, RESP) as

    (

    Select 1, null, 'Y' from dual union all

    Select 2, 1, "n" of all the double union

    Select option 3, 2, "n" of all the double union

    Select 4, 1, 'Y' from dual union all

    Select 5, 4, the double "n" of all union

    Select 6, 5, 'Y' from dual union all

    Select 7, 6, the double "n" of all union

    Select 8, 1, the double "n" of all union

    Select 9, 8, the double "n" of all union

    Select 10, 9, "Y" of the double

    )

    Select emp_id, mgr_id, RESP

    of mydata

    connect mgr_id = emp_id prior

    Start by emp_id = 1;

    EMP_ID MGR_ID RESP

    ---------- ---------- ----

    1            Y

    2 1 N

    3 2 N

    4 1

    5 4 N

    6 5

    7 6 N

    8 1 N

    9 8 N

    10 9 Y

    10 selected lines.

    Each employee has a Manager (self or the following in the upper hierarchy with RESP = 'Y')

    The root must be always charged.

    To find who is responsible for a certain employee ID, I can run the following query:

    I... responsible e: emp_id = 7 is 6

    Select emp_id, mgr_id, RESP

    of mydata

    When resp = 'Y '.

    and rownum < = 1

    Connect prior mgr_id = emp_id

    Start by emp_id = 7;

    EMP_ID

    ----------

    6

    1 selected line.

    i.e.: head = emp_id is 1/9

    Select emp_id

    of mydata

    When resp = 'Y '.

    and rownum < = 1

    Connect prior mgr_id = emp_id

    Start by emp_id = 9;

    EMP_ID

    ----------

    1

    1 selected line.

    i.e.: Manager emp_id = 4 is auto

    Select emp_id

    of mydata

    When resp = 'Y '.

    and rownum < = 1

    Connect prior mgr_id = emp_id

    Start by emp_id = 4;

    EMP_ID

    ----------

    4

    1 selected line.

    What query is the fastest to get all employees to a certain level of responsibility?

    That is to say: all employees not responsible according to 1 should give:

    EMP_ID MGR_ID RESP

    ---------- ---------- ----

    2 1 N

    3 2 N

    8 1 N

    9 8 N



    Kind regards.

    Alberto

    Hi, Alberto.

    So, you want to quit looking more far down the tree when you come to a node with an RESP = 'Y', right?

    Just include an RESP = ' don't (or resp. <> 'Y' or NVL (RESP, 'Y' <> 'Y') in the CONNECT BY State, like this:)

    Select emp_id, mgr_id, RESP

    of mydata

    connect mgr_id = emp_id prior

    and RESP = "n"-* NEW *.

    Start by emp_id = 1;

  • pivot query question

    I have a query in Oracle 11:
     select to_char(da,'DY-DD') days
    from (
            select rownum -1 + to_date('2012-10-15','yyyy-mm-dd') da, l
            from   (select level l
                    from   dual  connect by level <= to_date('2012-10-21','yyyy-mm-dd') - to_date('2012-10-15','yyyy-mm-dd')+1)
            order by 1) 
    Result
    "DAYS"
    MON-15
    TUE-16
    WED-17
    THU-18
    FRI-19
    SAT-20
    SUN-21
    What I need which is present in a row instead of a column:
     MON-15  TUE-16  WED-17  THU-18  FRI-19  SAT-20  SUN-21
    This should be done with pivot requests? Any suggestion please!
    Thanks in advance.

    Hello

    user564819 wrote:
    I need in 7 different columns.
    Oracle version is 11.2.0.1.0. Could you give an example of how to do this with pivot query?

    Here's one way:

    WITH     all_days     AS
    (
         SELECT     LEVEL  AS n
         ,     TO_CHAR ( TO_DATE ('2012-10-15','yyyy-mm-dd') + LEVEL - 1
                   , 'DY-DD'
                   )     AS dy_dd
         FROM    dual
         CONNECT BY  LEVEL <= TO_DATE ('2012-10-21','yyyy-mm-dd') + 1
                            - TO_DATE ('2012-10-15','yyyy-mm-dd')
    )
    SELECT     *
    FROM     all_days
    PIVOT     ( MIN (dy_dd)
           FOR  n  IN (  1  AS col_1
                          ,  2  AS col_2
                          ,  3  AS col_3
                          ,  4  AS col_4
                          ,  5  AS col_5
                          ,  6  AS col_6
                          ,  7  AS col_7
                          ,  8  AS col_8
                          ,  9  AS col_9
                          , 10  AS col_10
                   )
          )
    ;
    

    This always displays exactly 10 columns.
    If the subquery produces less than 10 dates, then the last columns will be NULL.
    If the subquery produces more than 10 dates, will be not shown the 11th (and later versions).

    There is nothing special about the number 10; You can have any number of columns you want. The number of columns and their names is fixed when you write the query, regardless of what is in the subquery. If you want a dynamic number of columns, or names derived from data, see {message identifier: = 3527823}

  • Hierarchical query question (2)

    -Oracle Database 11 g Enterprise Edition Release 11.1.0.6.0 - 64 bit Production

    I'm putting together the two hierarchies. The first is the Center and the center of each parent to the top. The second attribute for each lower level is centre and it all the way to the top. Two hierarchies are in the same TABLE. An attribute if there is a Center in the ParentAttribId COLUMN (Conversely, the id COLUMN in this TABLE may be Centers.) Ultimately, the data will be listed record by record, with all parents in the form of columns.

    The query hierarchy Center works. The parent column records effort will be later, I worry about it right now. What I am struggling with is how to reach to get id from the Center in the attribute hierarchy. The fragment of the query (in the second ETC) trying to recover Center.Id, who is not in the scope, because it is included in the START WITH clause. But how to include in the FROM clause (to bring it within the scope), when it has nothing to do with the hierarchy (other than the starting point).

    < PRE >
    WITH
    Center_List_Hierarchy
    AS
    (
    SELECT
    -List 4) of the hierarchy of each Center, the level and the id.
    --
    -Note: by definition, CONNECT_BY_ROOT ModelId == ModelId ==: model.
    -ModelId returned to not use: model (in the outer query).
    CONNECT_BY_ROOT Id Center_Root,
    Center_Level LEVEL,
    ModelId model,
    ID
    Of
    ADMINEPO. PP_Respcenter
    CONNECT
    (--3) for each Center, go to (and understand) top, identified by Id = ParentId.
    ModelId = ModelId PRIOR
    AND Id = ParentId PRIOR
    AND PREREQUISITE Id & lt; & gt; ParentId PRIOR
    START BY
    (ModelId, Id)     IN
    (
    SELECT
    Attribute.ModelId,
    Attribute.Id
    Of
    ADMINEPO. PP_Respcenter_Name Center_Name,
    ADMINEPO. Attribute PP_AT_RespCenter
    WHERE
    (1) for this model, find the id of the list attribute.
    Center_Name.ModelId =: model
    AND Center_Name.LangId =: Name_Type_Default
    AND UPPER (Center_Name.NAME) = "LIST of CENTER.
    (--2) get all the centres associated with the attribute.
    AND Attribute.ModelId = Center_Name.ModelId
    AND Attribute.ParentAttribId = Center_Name.Id
    )
    ),
    Attribute_Hierarchy
    AS
    (
    SELECT
    (--4) for this Center, get each attribute with its hierarchy.
    Center.Id Center,
    CONNECT_BY_ROOT Id Attribute_Root,
    Attribute_Level LEVEL,
    ModelId model,
    ID
    Of
    ADMINEPO. PP_Respcenter
    CONNECT
    (--3) for each attribute, go to (and understand) top, identified by Id = ParentId.
    ModelId = ModelId PRIOR
    AND Id = ParentId PRIOR
    AND PREREQUISITE Id & lt; & gt; ParentId PRIOR
    START BY
    (ModelId, Id)     IN
    (
    SELECT
    Attribute.ModelId,
    Attribute.ParentAttribId
    Of
    Center_List_Hierarchy Center
    ADMINEPO. Attribute PP_AT_RespCenter
    WHERE
    (1) limit to the low level of the centres.
    Center.Center_Level = 1
    (--2) get his attributes.
    AND Attribute.ModelId = Center.Model
    AND Attribute.Id = Center.Id
    )
    )
    < / PRE >

    Hello

    Sorry, I don't understand.

    Whenever you have a problem, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all the tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    If you can show your problem using tables commonly available, such as scott.emp or hr.employees (which contains hierarcies) so you don't have to display the sample data; just results and explanations.

    Brian Tkatch wrote:
    ... What I am struggling with is how to reach to get id from the Center in the attribute hierarchy. The fragment of the query (in the second ETC) trying to recover Center.Id, who is not in the scope, because it is included in the START WITH clause.

    Isn't this Attribute_Root below?


    ...     Attribute_Hierarchy
    AS
    (
    SELECT
    (--4) for this Center, get each attribute with its hierarchy.
    Center.Id Center,
    CONNECT_BY_ROOT Id Attribute_Root,
    Attribute_Level LEVEL,
    ModelId model,
    ID
    Of...

  • Forms 6i update and query question

    Hello world
    I created a form in Forms 6i for the purpose of upgrading the existing data in my database and add data to empty columns in the same table. To create this form, I used the forms Assistant. In this form, I have 2 blocks of data that are associated as follows:
    BACK. SCHOOL_ID = UNO. SCHOOL_ID AND BACK. CLASS_ID = UNO. CLASS_ID. My first block is the main block called UNO and contains the following items: 1) teacher_id, grade 2), class_id) 3, 4) class_name. Teacher_id I bring when the user enters their credentials before entering the form. Class_id group has a record where I show all classes offered by this user. My second block called DOS is the retail block and have the following: 1) class_id,) 2 teacher_id, student_id) 3, 4.) grade_q1, 5) grade_q2, 6) semester_ex1, 7) grade_q3, 8) grade_q4, 9) semester_ex2, semester_1, 10)) 11 semester_2, 12) Final. Rules of forms to create a form that is used to update records in a table, says that the master block must be marked 'NO' in the option delete, insert and update. I have this as it should.
    My problem is that every user after the update a record, should continue to update other classes that belong to the same user, but when that user tries to go to class_id in the main block and run the search option by pressing F9, the user receives a message saying that this article is protected from editing, and the only way it works is that if you press on the button F7 to enter a query, then F8 to run this query, but the user must re-enter the new user.
    Is it possible to allow the user to find another class which belongs to the same user without having to retype your credentials again?

    Hello

    He or she has to do, is use the arrows keys to continue searching for the other classes.

    Why not use Lov...?

    Create KEY-LISTVAL trigger for the United Nations. CLASS_ID with code similar to the following:

    IF SHOW_LOV ('LOV_NAME') THEN  -- CLASS_LOV
            SET_BLOCK_PROPERTY ('DOS', DEFAULT_WHERE, 'CLASS_ID= ' || :UNO.CLASS_ID);
    
         GO_BLOCK ('DOS');
    
         EXECUTE_QUERY;
    
    ELSIF SHOW_LOV ('LOV_NAME') THEN  
    
    ......
    
    END IF;
     
    

    Re: Show_lov in Enter query mode does not.

    I hope this helps...

    Kind regards

    Abdetu...

  • Analytical query question

    Hi all
    I'm kinda new in the analytical work with query and have a moment difficult to achieve what I wanted.
    Here is the script to create the table and insert data.
    create table temp_ar1 (lkey NUMBER,
    amount NUMBER
    )
    ;
    Insert the Script-
    Insert into temp_ar1 values (1, -2.5);
    Insert into temp_ar1 values (1, -10);
    Insert into temp_ar1 values (1, 5);
    Insert into temp_ar1 values (2, 0);
    Insert into temp_ar1 values (2, -5);
    Insert into temp_ar1 values (2, 2);
    Insert into temp_ar1 values (2, -1);
    
    
    With main_table as 
    (
    select lkey,amount
          ,case when amount > 0 then
            'positive'
            else
            'negative'
            end col1
    from temp_ar1
    )
    ,Temp_A as
    (
    Select O.*
         ,Sum ( case when col1 = 'negative' then amount
                    else null
                    end ) Over (partition by col1,lkey) as sumcol1
                    
          ,Sum ( case when col1 = 'positive' then amount
                    else null
                    end ) Over (partition by col1,lkey) as sumcol2
                   
      from main_table  O
     )
      select  lkey,amount,col1,sumcol1,sumcol2
     from Temp_A order by lkey
    
          LKEY     AMOUNT COL1        SUMCOL1    SUMCOL2
    ---------- ---------- -------- ---------- ----------
             1          5 positive                     5
             1       -2.5 negative      -12.5
             1        -10 negative      -12.5
             2         -1 negative         -6
             2          2 positive                     2
             2          0 negative         -6
             2         -5 negative         -6
    
    7 rows selected.
    I'm trying to get the result that resembles
    lkey , sumcol1 , sumcol2 
    1       -12.5    5
    2       -6      2 
    So for each separate key, I should get only a line that has sumcol1 (which is the sum of a negative amount for this key) and
    sumcol2 (which is the sum of the positive amount for this key)

    Really appreciate your help on this matter.

    or, if you do not want to group by;

    SQL> with Temp_A as
      2  (
      3  select O.*
      4    ,sum ( case when amount < 0 then amount
      5                  else null
      6           end ) over (partition by lkey) as sumcol1
      7    ,sum ( case when amount > -1 then amount
      8                else null
      9           end ) over (partition by lkey) as sumcol2
     10    ,row_number() over (partition by lkey order by lkey) rn
     11    from temp_ar1  O
     12   )
     13  --
     14  select  lkey,sumcol1,sumcol2
     15  from Temp_A
     16  where rn = 1
     17  /
    
          LKEY    SUMCOL1    SUMCOL2
    ---------- ---------- ----------
             1      -12.5          5
             2         -6          2
    
  • Query question queries

    You can query a query created using queryNew()?

    When I try the following code, I get an error:

    "Query of queries syntax error.
    Meeting "qData. user. "Incorrect conditional expression, waiting for an a [as | null | between | in | comparison] condition."

    Code:

    < cfset qData = queryNew ("tool, user, community, fm01, fm02, fm03, fm04, fm05, fm06, fm07, fm08, fm09, fm10, fm11, fm12, fy") >
    < cfset temp = #queryAddRow (qData) # >
    < cfset temp = #querysetCell (qData, "tool", "empty") # >
    < cfset temp = #querysetCell (qData, "user", "Bob") # >

    < cfquery dbtype = "query" name = "chkQdata" >
    SELECT *.
    OF qData
    WHERE qData.user = 'Bob '.
    < / cfquery >

    I just tried the code you provided, adding two cfdump Tags (the first to empty the qData query and the second to empty the chkQdata query). Everything worked well exactly as you had it on Railo 3.1. It did not work (threw the error you got) on CF 8.0.1.

    If I deleted the WHERE clause of the query of chkQdata, it runs (no error) in CF 8.0.1.

    For that it works as you want in CF8, change the user column. This seems to be a keyword for CF8. While I didn't check exactly, if I change your original request to be 'empty' = tool, it runs. In addition, rename the column user usr generates the script runs correctly.

    Here is the code that I had to work in CF8 and Railo 3.1:

    SELECT *.

    OF qData

    WHERE the usr = "Bob."

Maybe you are looking for