doubt in the case when statement

Hi the gems...

I have a case when statement in a select clause... ago total three conditions in the case when statemnt.

now my question is if all theconditions gets mapped, what happens?

is only the first condition is executed and rest two is ignored or the third condition will overwrite the previous two?

Please help... Thanks in advance...

You can see it with:

select case when 1=1 then 1
            when 2=2 then 2
            when 3=3 then 3
       end test
from dual;

TEST
---------
1

You get only the first result!

Published by: hm on 18.11.2011 04:11

Tags: Database

Similar Questions

  • using case when statement or decode unfavorable in where clause

    Hi the gems...

    I have a problem in the following query...
    I try to use when case statement in where clause of a select query.


    Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
    CR. Salary salary
    of customer_details cr
    where (case when ' > ' = ' > ' then ' cr.salary > 5000')
    When ' > ' = ' < ' then ' cr.salary < 5000'
    When ' > ' = '=' and then 'cr.salary = 5000'
    Another null
    (end);


    the expression in the when clause of the statement of the case, when comes from HQ and according to the choice I have to make the where clause.
    That is why, for the execution of the query, I put ' > ' in this place.

    If the original query will look like this (for reference):

    Select cr.customer_name. ' - ' || CR.customer_number as cust_name,
    CR. Salary salary
    of customer_details cr
    where (case when variable = ' > ' then ' cr.salary > 5000')
    When the variable = ' < ' then ' cr.salary < 5000'
    When the variable = '=' and then 'cr.salary = 5000'
    Another null
    (end);


    so, in a real case, if the user selects ' > ' then the filter will be ' where cr.salary > 5000.
    If the user selects ' < ' then the filter will be ' where cr.salary < 5000.
    If the user selects '=', then the filter will be 'where cr.salary = 5000 '.

    but I get the error "ORA 00920:invalid relational operator.

    Help, please... Thanks in advance...

    Hello

    select cr.customer_name || ' - ' ||cr.customer_number as cust_name,
           cr.salary                                      as salary
     from customer_details cr
    where (    v_variable = 'bigger'
           and cr.salary > 5000
          )
       or (    v_variable = 'less'
          and cr.salary < 5000
           )
       or (    v_variable = 'eq'
            and cr.salary = 5000
           )
    

    Published by: user6806750 on 22.12.2011 14:56
    For some reason that I can't write in sql "<', '="">", "=".

  • Select the case when several returnvalue? 20 D

    Hello
    I would like to know if there is a solution less than 10g for something like this

    Select case when 'C' = 1
    then
    (select double 1,2,3,4,5)
    on the other
    (select double 6,7,8,9,0)
    end
    of the double.
    (select 1 double 'C')

    What I really need, is the full output of (select double 1,2,3,4,5) or (select double 6,7,8,9,0) If a State due to a different sql query is true or false. No matter if the solution uses 'case when' or anything else.

    Thanks in advance for any help.
    Best regards
    Carsten

    Something like this would work with the example you gave.

    SQL> with test_data as
      2      (select 1 c from dual)
      3  select
      4      1, 2, 3, 4, 5
      5  from
      6      dual,
      7      test_data
      8  where
      9      c = 1
     10  union all
     11  select
     12      6, 7, 8, 9, 0
     13  from
     14      dual,
     15      test_data
     16  where
     17      c != 1;
    
             1          2          3          4          5
    ---------- ---------- ---------- ---------- ----------
             1          2          3          4          5
    
    SQL> edi
    Wrote file afiedt.buf
    
      1  with test_data as
      2      (select 2 c from dual)
      3  select
      4      1, 2, 3, 4, 5
      5  from
      6      dual,
      7      test_data
      8  where
      9      c = 1
     10  union all
     11  select
     12      6, 7, 8, 9, 0
     13  from
     14      dual,
     15      test_data
     16  where
     17*     c != 1
    SQL> /
    
             1          2          3          4          5
    ---------- ---------- ---------- ---------- ----------
             6          7          8          9          0
    
  • Add case/When statement to display

    I am trying to add the Sub instruction 'case' in my opinion, but I get an error "invalid identifier" where he currently is now.

    CASE

    WHEN LATEST_EVENT_DT < "the Max event Date".

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as 'Max Event'

    CREATE OR REPLACE FORCE VIEWS GREATEST_DATE_VW_SGD
    ("PCFN"
    , "TCN.
    , "LATEST_EVENT_DT".
    , "LATEST_EVENT_DESC".
    , "OIT_Closed_Date".
    , "OIR_Closed_Date".
    , "OIN_Closed_Date".
    , "The Max event date".
    "Max Event")

    AS
    SELECT

    MV. PCFN,

    MV. TCN,

    MV LATEST_EVENT_DT.

    MV LATEST_EVENT_DESC.

    ILO. CLOSED_DATE,

    OIR. CLOSED_DATE,

    ISO. CLOSED_DATE,

    largest (mv. LATEST_EVENT_DT
    nvl (ILO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))
    nvl (OIR. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))
    nvl (ISO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))
    ) AS "event of Max Date."

    CASE
    WHEN LATEST_EVENT_DT < "the Max event Date".
    THEN "CANCELLED."
    OF OTHER LATEST_EVENT_DESC
    END as 'Max Event'

    OF APEX01. SGD_CIET_NDN_ROUTES_MV mv

    LEFT OUTER JOIN APEX01. OEF_ITV_TALLINN ILO ON mv. PCFN = ILO. PCFN AND mv. TCN = ILO. TCN

    LEFT OUTER JOIN APEX01. IRO OEF_ITV_RIGA ON mv. PCFN = IRO. PCFN AND mv. TCN = IRO. TCN

    LEFT OUTER JOIN APEX01. ISO of OEF_ITV_NDN ON mv. PCFN = ISO. PCFN AND mv. TCN = ISO. TCN;

    Is this possible? or do I have to create another view just for the case of "Max Event?

    CREATE OR REPLACE FORCE VIEW MAX_EVENT_DESC_SGD ('Max Event')

    AS

    SELECT THE CHECK BOX

    WHEN LATEST_EVENT_DT < "the Max event Date".

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as the "last event".

    OF greatest_date_vw_sgd g;

    Thank you

    Steven

    Post edited by: StevenD609

    Hello.

    Today, there is already this question...

    CREATE OR REPLACE FORCE VIEWS GREATEST_DATE_VW_SGD

    ("PCFN"

    , "TCN.

    , "LATEST_EVENT_DT".

    , "LATEST_EVENT_DESC".

    , "OIT_Closed_Date".

    , "OIR_Closed_Date".

    , "OIN_Closed_Date".

    , "The Max event date".

    "Max Event")

    AS

    SELECT

    Z.*,

    CASE

    WHEN LATEST_EVENT_DT< "max="" event="">

    THEN "CANCELLED."

    OF OTHER LATEST_EVENT_DESC

    END as 'Max Event'

    Of

    (

    SELECT

    MV. PCFN,

    MV. TCN,

    MV LATEST_EVENT_DT.

    MV LATEST_EVENT_DESC.

    ILO. CLOSED_DATE,

    OIR. CLOSED_DATE,

    ISO. CLOSED_DATE,

    largest (mv. LATEST_EVENT_DT

    nvl (ILO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))

    nvl (OIR. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))

    nvl (ISO. Closed_Date, TO_DATE ('01011950', 'MMDDYYYY'))

    ) AS 'Max event Date.

    Of

    APEX01. SGD_CIET_NDN_ROUTES_MV mv

    LEFT OUTER JOIN APEX01. OEF_ITV_TALLINN ILO ON mv. PCFN = ILO. PCFN AND mv. TCN = ILO. TCN

    LEFT OUTER JOIN APEX01. IRO OEF_ITV_RIGA ON mv. PCFN = IRO. PCFN AND mv. TCN = IRO. TCN

    LEFT OUTER JOIN APEX01. ISO of OEF_ITV_NDN ON mv. PCFN = ISO. PCFN AND mv. TCN = ISO. TCN

    ) Z ;

  • Need help with CASE When statement in a Where Clause

    So I have a SQL (simplified for this forum)

    Select t1.*
    from table1, table2 t2 t1
    where t1.field1 = t2.field1
    and when t1.field2 is null then trunc (sysdate) < = trunc (t1.date1 + 17)
    of another trunc (sydate) > = end of trunc (t2.date2 + t2.date3)

    I end up getting an error ORA-00905: lack of keyword

    I'm sure that I just got something here involved.

    You can not make the comparison within the statement underlying case like this. Assuming you have appropriate data types, something like this should work

    Select t1.*
    from table1 t1, table2 t2
    where t1.field1 = t2.field1
      and ((t1.field2 is null and
            trunc(sysdate) <= trunc(t1.date1 + 17)) or
           trunc(sydate) > = trunc(t2.date2 + t2.date3))
    

    John

  • Using the Combobox options in the case of statements

    If anyone can help me I would be really grateful. I am building a calculator to do something specific. I have a combobox with 2 options. The option determines the equation which is therefore performed on a figure of entry into the next area. I have my if statement, I don't know how to code the option of the combobox. Here's what I have so far:

    calc_btn.addEventListener (MouseEvent.CLICK, calcClick);

    rvalue. Border = true;

    rvalue. Restrict = "0-9";

    var rateablevalue:String;

    var calcRes:Number;

    function calcClick(event:MouseEvent):void {}

    rateablevalue = rvalue.text;

    if (cb1 == {label: "3 month"}) {}

    calcRes = parseInt (rateablevalue) / 100 * 8.625;

    calcRes.toString ();

    results_txt.text = String (calcRes);

    { } ElseIf (cb1 == {label: "6 month"}) {}

    calcRes = parseInt (rateablevalue) / 100 * 17.25;

    calcRes.toString ();

    results_txt.text = String (calcRes);

    }

    }

    Anyone see where I am going wrong with combobox (cb1)?

    Thank you very much in advance to take a peek.

    Your conditional statements are not piloted the ComboBox selection if this is the intention.  Try to change the t

    o the shape of...

    If (cb1.selectedItem.label == "3 months") etc...

  • Firefox OS INDIA is available? It is available for nokia phones? If this isn't the case, when it comes in INDIA?

    can I try on SYmbian or Android phone?

    Hi, I had same query in my mind. For now the best option is to open the ZTE from e - bay. And in my opinion try filed on android will not be a good option for the moment.

  • any case when and the sql clause

    Hello:
    What follows is my sql clause:
    SELECT T.*, b.name
    OF dbtest1 t
    LEFT OUTER JOIN dbtest b ON t.NO = b.empno
    WHERE t.ChineseName like '% "| : ChineseName | ' %' AND b.name like "%" | : name | » %'
    ORDER BY t.ChineseName

    The main problem is that I want to check the b.name if it is null, it can be passed as function NVL, so I try using case when, but it does not work.
    When there are the b.name in where clause, the columns of result will not include data without b.name (or implies the b.name is NULL); And that
    the result data are not entirely accurate.
    is it possible to use the case when it is implemented in the following code snippet:

    -case when b.name is not NULL then b.name like "%" | : name | » %'
    Else b.name = NULL (b.name = b.name does not seem to work on the analysis of data zero)
    end

    Thank you very much.

    962769 wrote:
    The main problem is the table is the form of the cross, and the like clause will filter the
    data without a name. Basically, it should show the empty columns, however, it won't.
    so, when I test the sql code, I fhound Like "%" | b.Name | ' %' will not get the data when the original dbtest1 table data
    has no id corresponding to the BD test. It seems pointless to go the LEFT OUTER JOIN.

    Thank you

    WHERE t.ChineseName like '%'||:ChineseName||'%'
    AND  (
            b.name like '%'||:name||'%'
           or b.empno is null
        )
    
  • cases when for several columns

    Hello, Experts

    Could help me please on the function below. ?

    How to call two different columns in the instruction box.

    I'm migrating some of the BO decode OBIEE11g reports to help can we able to reach below senario in BO-universe but I don't know how we can achieve this in RPD - OBIEE 11 g

    DECODE (TABLE.NAME_1. Column_name, 'Client Meeting passwords', TABLE_NAME2. COLUMN, NULL)

    Concerning

    Sri

    Thanks for the reply Ceresa... !

    I use Case when statement... but I could not able to include more than one Table_Name.Coulmn_Name. the RPD

    For Ex in BO_Universe, it's logic has been used: DECODE (RPT.CUST_INFO.INFO_SUBTYPE,'Customer has past, RPT.) CUST_INFO. BODY, NULL)

    OBIEE: I'm trying to use like this: case when RPT.CUST_INFO.INFO_SUBTYPE,'Customer has past AND the RPT words. CUST_INFO. BODY = "NULL") END.

    ERROR: [nQSError: 27002] near <=>: syntax error [nQSError: 26012].

    Please guide me I missed something in the formula... ?

    I thank in advance. !

    Sri

  • What is the difference in the case of stmt

    Hello
    I get the same result with the following case
    SQL> select (case when empno=7566 then 100 else empno end)
      2  from emp;
    
    (CASEWHENEMPNO=7566THEN100ELSEEMPNOEND)
    ---------------------------------------
                                       7369
                                       7521
                                        100
                                       7654
                                       7698
    
    
    SQL> select (case empno when 7566 then 100 else empno end)
      2  from emp;
    
    (CASEEMPNOWHEN7566THEN100ELSEEMPNOEND)
    --------------------------------------
                                      7369
                                      7521
                                       100
                                      7654
                                      7698
    Apart from this we have no difference between the 2 above cases

    Thank you

    There is no difference in your two case statements. They represent the same logic, and that's why you get the same result.

    There are two ways to use the case as statements evidenced as well.

    "CASE deptno when 10 then...". "is used when we want to match the exact value by using the equality operator. It's the same as 'BOX when deptno = 10 then... ". »

    "CASE when deptno > 10 then...". "is used when the operator is none other than the equality operator"="like" >,<, like,bewteen="" etc"="">

    I thing you got the point.

    Concerning

    Published by: MYRIAM on November 4, 2008 21:44

  • When I use hotmail to respond to an email, the content of the mail I answer not included. How can I keep the content of the email when I forward or reply to mail?

    How to keep the content of the email (hotmail) in firefox when in front or answer email. This is not the case when I use Internet Explorer.

    See this:
    https://support.Mozilla.com/en-us/KB/blank+messages+in+Hotmail

  • Is there a delay in the signal when using Bluetooth on any iDevice and, in particular, on an iPad Pro?

    I am using Bluetooth involved in the use of music made a software with sounds of digital instruments using a musical keyboard hardware connected via the USB cable to Lightning to play sounds from the app on my iPad Pro.

    When I try to use a Bluetooth speaker source, there's a 1-2 second delay when I play a chord in the app and when the sound is played through the Bluetooth speaker.

    This delay IS NOT the case when I use just the iPad Pro speaker on when I am attaching some small travel speakers to the headphone jack of my iPad.

    Only when I try to use my Bluetooth speakers sounds better.

    I use a keyboard master Korg MicroKey Air uses the USB port play their own Korg music make its app module.

    Someone who makes music on an iPad with this problem at all?

    Is this a problem question Bluetooth and/or iOS?

    My iPad Pro isn't very strong using these apps do and travel speakers I use plugged into the headset jack music are a little better on the volume, but tend to deform when I try to increase the overall volume level.

    I intend to put this issue on the web forums for Korg, but want some answers from anyone who has been playing and recording music on their iPad using an external keyboard to play and record music in an app to do the music.

    Also, (and I intend to ask this in the GarageBand for iOS forums) can the iOS version of Garageband output sound on a Bluetooth speaker and quietly delay, too, that I can not get the iOS version of GarageBand to sound output via Bluetooth to a Bluetooth speaker.

    Hi, MichelPM

    According to the used speaker, he will always be * some * delay when using Bluetooth to stream audio from an iOS device (or practically any device BT also) through a Bluetooth speaker. I have a Bluetooth speakers system cheaper that I use with my iPad mini 4... I pretty much use it only to listen to sound. If I try and use it for Pinball iOS games I play, there is a delay of environ.5 second anywhere, I'm the speaker. Exactly same phenomenon occurs with the keyclicks when you type it on the iPad keyboard... 5 second delay & even with some applications of synthesizer iOS that I use (Animoog & Arturia iSEM). I think it's just the nature of the beast of Bluetooth.

    Higher quality speakers would be better, but I'm not spending more money to find out.

    If you want an immediate response with zero real audio keypress delay, I fear, the only way to do this is to use a wired speaker.

  • Interview with case/when &amp; sum() over (partition) producing unexpected lines

    Since some time ago, I asked a question in this forum on an unusual problem of join and subtract ( subtract the total periods of highest level duration ). I had what seemed like a work request. So far, I could not really use it. Now that I'm looking closer results, I think that there is something wrong with it, but I can't understand why it's happening.

    Using the definition of the table of the original question, the following simple query shows a special extract of the data I'm looking at.

    Select duration, event_type, start_time, code_range, request_id from MYTABLE where REQUEST_ID = 'abc '.

    This translates into the following lines (separate columns by ' / '):

    START_TIME/REQUEST_ID/EVENT_TYPE/CODE_RANGE/DURATION
    2010-11-12 01:42:04.0/abc/Junk/publicEntryPoint/2,003
    2010-11-12 01:42:04.0/abc/Junk/webServiceCall/947
    2010-11-12 01:42:04.0/abc/Junk/webServiceCall/969

    Another similar request with REQUEST_ID = 'def' means:

    START_TIME/REQUEST_ID/EVENT_TYPE/CODE_RANGE/DURATION
    2010-11-12 00:22:13.0/def/junk/webServiceCall/788
    2010-11-12 00:22:13.0/def/junk/webServiceCall/1,128
    2010-11-12 00:22:13.0/def/junk/publicEntryPoint/2,003

    What follows is an excerpt simplified query I have a problem with:

    Select value start_time request_id event_type, code_range, duration, case code_range
    When "publicEntryPoint" then length * 2 - sum (duration) over (partition by request_id)
    of another-1
    end inner_duration from MYTABLE where EVENT_TYPE = 'spam' and trunc (START_TIME) = to_date('2010-11-12','yyyy-mm-dd')
    and rownum < 1000;

    Notice the couple of unconventional functions used here, the ' case/when' and 'sum() over (partition).

    This property returns a bunch of lines (count: 999), but here are the two with the particular REQUEST_ID values:

    START_TIME/REQUEST_ID/EVENT_TYPE/CODE_RANGE/DURATION/INNER_DURATION
    2010-11-12 01:42:04.0/abc/junk/publicEntryPoint/2,003/2,003
    2010-11-12 00:22:13.0/def/junk/publicEntryPoint/2,003/87

    The second line is correct. The first line has an unexpected value of INNER_DURATION of 2003. It should be 87 as the second row. I don't understand why this is happening.

    I think that 'and rownum '.<1000" must="" be="" the="" problem.="" it="" must="" be="" excluding="" some="" of="" the="" rows="" needed="" for="" the="" sum.="" the="" analytic="" function="" will="" be="" applied="" after="" this="" condition--see="" the="" sql="">

    Analytical functions are the last set of operations performed in a query, except for the
    final ORDER BY clause. Every joint and every WHERE, GROUP BY and HAVING clauses are
    completed before the analytical functions are processed

    Have you tried the query without this condition?

    Kind regards
    Bob

  • Syntax of the case statement / WHEN

    The table I use a depreciation per fiscal year and the fiscal period.  I try to have the amount of depreciation to go to 2 different columns based on the fiscal year and the fiscal year.  I'm doing it with a nested case statement. I know that is not correct, because I get the message ORA-00905.  I'm relatively new to sql and it is contribtuing to my problem as well.  Here is the code I have and suggestions / corrections would be appreciated.  Thanks for the help...

    SELECT

    lao PDR. DEPTID as DEPTID,

    lao PDR. ASSET_ID as ASSET_NO,

    PA. Descr as DESCRIPTION,

    lao PDR. ACCOUNT_AD as AD_ACCT,

    PDL. DE_ACCT, to take into ACCOUNT

    lao PDR. ADEATH as AMT_DEPR,

    PDL. JOURNAL_ID as JRNL_ID,

    PDL. JOURNAL_DATE as JRNL_DT,

    lao PDR. FISCAL_YEAR as FY,

    lao PDR. ACCOUNTING_PERIOD AP,

    CASE

    WHEN RDP. FISCAL_YEAR = 2014 THEN

    WHEN RDP. PERIOD ACCOUNTANT = 11 THEN pdr. DEPR

    END AS CURR_MONTH,

    CASE

    WHEN RDP. FISCAL_YEAR <>2014

    WHEN RDP. ACCOUNTING PERIOD <>11 THEN pdr. DEPR

    END AS PRIOR_MONTH

    OF PS_DEPR_RPT pdr

    INNER JOIN PS_DIST_LN pdl

    THE pdl. BOOK = pdr. BOOK

    AND pdl. BUSINESS_UNIT = pdr. BUSINESS_UNIT

    AND pdl. FISCAL_YEAR = pdr. FISCAL_YEAR

    AND pdl. ACCOUNTING_PERIOD = pdr. ACCOUNTING_PERIOD

    AND pdl. ASSET_ID = pdr. ASSET_ID

    AND pdl. CF_SEQNO = pdr. CF_SEQNO

    INNER JOIN PS_ASSET PA

    WE pa. ASSET_ID = pdl. ASSET_ID

    AND pa. BUSINESS_UNIT = pdl. BUSINESS_UNIT

    WHERE

    lao PDR. BUSINESS_UNIT = "A0465.

    AND pdr. BOOK = 'RUN '.

    AND ((pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 11) OR (pdr. FISCAL_YEAR = 2014 AND pdr. ACCOUNTING_PERIOD = 10))

    Hello

    2713822 wrote:

    Thank you... I appreciate the information you provide when you answer these questions.  I always try to get the amount (from the same column) for 2 rows in different columns.  I tried the LAST_VALUE and LAG but it took a long time for the queries to run, I'm looking for another way to do the same.  I'm only using SQL to retrieve data.  I don't have the ability to create or insert.

    I looked the information above and the CASE statement to look like this:

    CASE

    WHEN RDP. FISCAL_YEAR = 2014

    AND pdr. ACCOUNTING_PERIOD = 11

    THEN the RDP. ADEATH AS CURR_MONTH

    ON THE OTHER

    lao PDR. ADEATH AS MONTHS PREVIOUS

    END

    But I'm now getting an "ORA-00905: lack of keyword" message.

    What I'm trying to do is to draw 2 lines 1 to 2014 / 11 and another for 2014 / 10.  The amount for the period 2014 / 11 should go in the current column and the amount for the period 2014 / 10 should go in the previous column.

    Before current assets management

    01 AB01 50.01 50.03

    ....

    If you want to give an alias for a column, then you can say "AS nome_alias" after that tell you what that is in this column.

    'AS nome_alias' applies to the entire column.  Cannot use 'alias_name' in the middle of an expression, for example, in the middle of a CASE expression, before the END keyword.

    If you want to have 2 separate output columns, curr_month and prior_month to your output, you must then 2 separate columns in your SELECT clause.  for example:

    SELECT pdr.branch

    pdr.asset

    CASE

    WHEN pdr.fiscal_year = 2014

    AND pdr.accounting_period = 11

    THEN pdr.depr

    END AS curr_month

    CASE

    WHEN...

    THEN...

    END AS prior_month

    PDR

    ;

    If post you some sample data (CREATE TABLE and INSERT statements), the results and explanations, I could show you how to complete the... sections.

    To find out what version of Oracle you have, use

    SELECT *.

    SINCE the release of v$.

    The output can be messy, like this:

    BANNER

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

    CON_ID

    ----------

    12 c Oracle database Release 12.1.0.1.0 - 64 bit Production

    0

    PL/SQL Release 12.1.0.1.0 - Production

    0

    CORE Production 12.1.0.1.0

    0

    AMT for 64-bit Windows: Version 12.1.0.1.0 - Production

    0

    NLSRTL Version 12.1.0.1.0 - Production

    0

    The important thing is the number 5 parts on the first line; 12.1.0.1.0 in the example above.

  • EXTRACT function can be used directly in the CASE statement WHEN

    I wrote the following SELECT statement. The function 'calc_time_diff' is a stored function that subtracts two timestamps and returns the result to the total number of seconds. My DBA does not 'calc_time_diff' as a stored function, then, I replaced the third line (in bold) in the SELECT statement with this:

    COUNTY ( BOX WHEN (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +)

    (extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

    (excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

    extract ((DEUXIÈME à PARTIR de v_end_ts-v_st_ts) < 3600 THEN 1 END) less_than_1_hrs_count

    But the CASE above does not work. It returns the same value as COUNT (*). If the total number of tickets is 32 output will be

    total_tickets less_than_1_hrs_count

    32                                 32

    If I call the "calc_time_diff" then I get the correct result. What I'm doing wrong here?

    **********************************************************************************************************************************************************************

    SELECT

    Count (*) total_tickets,

    COUNTY ( CASE WHEN END of calc_time_diff (t.created_date, h.closed_date) < 3600 THEN 1) less_than_1_hrs_count

    OF n01.cc_ticket_info t

    JOIN IN-HOUSE

    (SELECT ticket_id, MAX (created_date) closed_date

    OF n01.cc_ticket_status_history

    WHERE ticket_status = 'CLOSED' AND created_date > = 18 August 2013 ' AND created_date < (to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY)

    GROUP BY ticket_id

    ) h

    WE (t.ticket_id = h.ticket_id)

    INNER JOIN n01.cc_ticket_notes n

    WE (n.created_date = h.closed_date)

    WHERE (t. ticket_status = 'NOTIFICATION' t.ticket_status 'CLOSED' = GOLD) AND t.created_date > = 18 August 2013 ' AND t.last_changed < to_date('08/24/2013','MM/DD/YYYY') + interval '1' DAY);

    ***********************************************************************************************************************************************************

    create or replace

    FUNCTION calc_time_diff)

    p_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %,

    p_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %)

    RETURN NUMBER

    AS

    v_no_sec NUMBER;

    v_st_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

    v_end_ts N01.cc_ticket_info. Type of LAST_CHANGED %;

    BEGIN

    v_st_ts: = p_st_ts;

    v_end_ts: = p_end_ts;

    SELECT (extract (DAY OF v_end_ts-v_st_ts) * 24 * 60 * 60) +.

    (extract (HOUR FROM v_end_ts-v_st_ts) * 60 * 60) +.

    (excerpt (v_end_ts-v_st_ts MINUTE) * 60) +.

    excerpt ((SECOND from v_end_ts-v_st_ts)

    IN v_no_sec

    DOUBLE;

    Return v_no_sec;

    END calc_time_diff;

    Hello

    You don't need a function defined by the user or the EXTRACT to find the difference between two timestamps.

    SELECT COUNT (*) AS total_tickets

    , COUNTY ( BOX WHEN h.closed_date < t.created_date="" +="" interval="" '1'=""> )

                         THEN 1

    END

    ) AS less_than_1_hrs_count

    ...

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    If you change the query at all, post your modified version.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: https://forums.oracle.com/message/9362002

Maybe you are looking for