SELECT statement: summing up a positive and negative value

If I want to get the sum of the positive and negative values, can I do it like this?


Negative:
Select sum(amount) INTO negative_amt FROM order where amount like '%-%';
Positive:
Select sum(amount) INTO positive_amt FROM order where amount not like '%-%';
If this is not the case, how should I go about this?
SQL> SQL> With t As  2  (  3  Select   -100 c1 From dual Union All  4  Select -300    From dual Union All  5  Select -15.6    From dual Union All  6  Select 90    From dual Union All  7  Select 80    From dual Union All  8  Select 300    From dual Union All  9  Select -203.8    From dual Union All 10  Select 922.56    From dual 11  ) Select Sum(neg_num) neg_num, Sum(pos_num) pos_num 12    From 13    ( 14    Select Case When c1 < 0 Then c1 Else 0 End neg_num, 15           Case When c1 > 0 Then c1 Else 0 End pos_num 16    From t 17    ) 18  /

   NEG_NUM    POS_NUM---------- ----------    -619.4    1392.56

SQL>

Tags: Database

Similar Questions

  • How can I design square wave which has a positive and negative values equal to the other and separated from each other by controlled time or distance

    How can I design square wave which has a positive and negative values equal to the other and separated from each other by controlled time or distance, as indicated in the figure below. and enter this signal in a data acquisition.

    At the time wherever you go for the beautiful diadram, you could have done the vi

    Your DAQ would like a waveform (table of values and dt ak 1/sampling rate)

    If you set the sampling rate you know the length of the array, create a matrix of zeros and set the values of the two amplitudes...

    Because I don't want to connect other duties here are some photos

    And it does have a few drawbacks leaves to be desired in my solution, just think... rounding errors and what might happen if the tables are becoming more...

  • Calculate if got only positive and negative values

    I have this problem that I need help.

    I have this table called MESSAGES. There fields client_name and AMOUNT like this:

    MESSAGES*.

    CUSTOMER NAME_
    Amy
    Amy
    Amy
    Bill
    Cheryl
    Cheryl

    AMOUNT
    500
    -200
    -100
    -111
    50
    100


    As noted, my client AMY has 3 quantity: 500, -200, -100. I want my PL/SQL in order to calculate to summarize these amount if the amount of the same client_name 1 has a value negative and positive, and all remaining the same if all of its values is positive or negative.

    Result:

    CUSTOMER NAME_
    Amy
    Bill
    Cheryl
    Cheryl

    AMOUNT
    200
    -111
    50
    100

    How am I suppose to do?

    Hey lee,

    hope this helps

    SQL> SQL> Create Table lee_test As  2  (  3  Select 'Amy' Name,   500    amt    From dual Union All  4  Select 'Amy'    ,    -200          From dual Union All  5  Select 'Amy'    ,    -100          From dual Union All  6  Select 'Bill'   ,    -111          From dual Union All  7  Select 'Cheryl' ,    50            From dual Union All  8  Select 'Cheryl' ,    100           From dual  9  );
    
    Table created
    
    SQL> SQL> Select Unique  2         Name,  3         Case When min_sign != max_sign Then Sum(amt) over (Partition By Name Order By Name)  4         Else amt  5         End amt  6  From  7  (Select Name,  8         amt,  9         min(sign(amt)) over (Partition By Name Order By Name) Min_sign, 10         Max(sign(amt)) over (Partition By Name Order By Name) max_sign 11  From lee_test 12  ) 13  Order By 1;
    
    NAME          AMT------ ----------Amy           200Bill         -111Cheryl         50Cheryl        100
    
    btw: are you chinese (cantonese??)
    
  • Positive and negative frequency of calculation deviation

    Hello

    IAM with PXI-5620 to measure RF PXI 5600.

    I need to measure the frequency deviation, Positive and negative. The example or vi "MT DAMA demodulate FM.vi" gives peak frequency deviation . Can any please help me find the positive frequency Deviation and negative frequency deviation of her

    Thank you

    Niju.

    Hi Johanna,.

    First things first - 5620 5600 + combined is what we call a PXI-5660 RF Signal Analyzer.

    The PXI-5660 module cannot be presence via the driver NOR-DAMA. The Modulation Toolkit FM sample that you reference is for the PXI-5661 and SMU-5663 analyzers, both use the driver NOR-DAMA.

    You use MT ni5660 FM demodulation. vi, located under the ni5660 examples.

    Now to your question...

    When you perform an FM demodulation, resulting the Subvi MT Demodulat FM data frequency / time with the frequency values (Y axis), is compared to the carrier frequency specified. Thus, data deviation of frequency (Hz), function of time. All you need to do to get the positive and negative frequency deviation is to use LabVIEW table Max & Min primitive functions of table palette. This will give you the min and max value of the FM data that will be the negative peak and the positive peak frequency deviation.

    Concerned,

    Andy Hinde

    RF systems engineer

    National Instruments

  • Guagewith scale positive and negative scale

    Hi all

    I thought it was simple. I need a gas reading of 0 to + or - 180 degrees either side of GUE positive readings figures up to 108 degrees, and the other side negative readings to-180 degrees

    Several skeins

    Greg

    1. use the text tool and enter the values on the ends of the scale.

    2 properties: scale. Enter the minimum and maximum values.

    3. other ways also exist, such as the nodes property.

    Lynn

  • positive and negative rotation numbers

    Hi all

    I create a roulette game that calculates the winning number based on the rotation of the main wheel. I'm if/else using statements to determine the winning number based on the rotation. I am tracking the rotation in the output panel. I want my rotation to go between 0 and 360, but the output panel trace 0-180, then it starts from "-180-0."

    The wheel can turn several times. No idea how to keep the positive numbers between 0 and 360, and do not have to write my if else to accommodate negative numbers?

    Thank you!

    var rot: Number = (whatever._rotation+360)%360;

  • the combination of two select statements to increase the maintainability and performance

    Hi SQL Experts,

    I use the Version of Oracle 11g DB and got both of the statements below.

    My mind can´t get his head around it how and if these two can be combined.

    They look like they could, but I can't figure out how... and I don't mean with a UNION ALL operation

    My main goal is a gain in performance and maintainability.

    SELECT *.

    OF T_TEMP_42 T1 WHERE T1. MATRIX_2 IS NULL AND

    (T1. BL_CODE | T1. YASSINE | T1. MATRIX_1 | T1. FIRMTYPE)

    PO NO

    (

    SELECT BL_CODE. YASSINE | MATRIX_1 | FIRMTYPE

    OF T_TEMP_41, WHERE MATRIX_2 IS NULL).

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

    SELECT *.

    OF T_TEMP_42 T1 WHERE T1. MATRIX_2 IS NOT NULL AND

    (T1. BL_CODE | T1. YASSINE | T1. MATRIX_1 | T1. MATRIX_2 | T1. FIRMTYPE)

    PO NO

    (

    SELECT BL_CODE. YASSINE | MATRIX_1 | MATRIX_2 | FIRMTYPE

    OF T_TEMP_41, WHERE MATRIX_2 IS NOT NULL

    );

    Thanks for your suggestions.

    Try this

    SELECT *.

    OF T_TEMP_42 T1

    WHERE (BL_CODE, YASSINE, MATRIX_1, FIRMTYPE, MATRIX_2) NOT IN (SELECT BL_CODE, YASSINE, MATRIX_1, FIRMTYPE, T_TEMP_41 MATRIX_2)

    It came off really simple... maybe too simple

  • angles, positive and negative area on a plot of polar

    Is there a way to label the sector on a polar plot angles with +/-values? We generate a lot of bosses of directivity of sonar and angles scored from-180 to 180 instead of 0 to 360 have long been the norm. Looking at the definition of the curve and Polar - display the tab - it doesn't seem to be an obvious way to do it.

    Hi Greg,.

    Unfortunately, there is no way to do in tiara at the moment. I presented a report of Corrective Action to resolve this (#323394), and I hope that this feature will be included in a future version of DIAdem. Thank you for that bring to our attention.

    Kind regards

    Jackie

  • Grid Y looking positive and negative in CS5

    I know there is another thread with discussion on why different programs the y axis upside-down, which is good.  The problem is that all the previous versions of Illustrator have your zero point as it would on a normal mathmatical grid.  Why now after 7 years of using Illustrator must I "Rethinking" how I move objects.  We create dielines and now if I put my text of the measure and captions on the top and bottom, to do the opposite of what we have done during all these years.  Besides the work placement.  Why is there not an option?  It's pathetic to from Adobe.  Someone please tell me there is an option to invert the y-axis now inverted.

    Monika said.

    Here it is:

    To change the origin of the rule in CS5 are the same as in CS4 and earlier versions, you can:

    (1) find and open the AIPrefs (Win talk) or Adobe Illustrator Prefs (Mac talk) of the file. It is a hidden file in the folder hidden settings of Adobe Illustrator CS5

    (2): find and replace the following two bits of code:

    /isRulerOriginTopLeft 1 > /isRulerOriginTopLeft 0 (replace the 1 with a 0)

    /isRulerIn4thQuad 1 > /isRulerIn4thQuad 0 (replace the 1 with a 0)

    Note: This is a global change.

  • Select the last Date of multicolumn and its value adjustent cust_id

    I have a Table with 5 customer_id and 5 Dates with each belonging to its cust_id.

    I need to take the last, in my example would be CUSTID_5.  I know

    this with the GREATEST who select the CHANGE_DATE_5 (in my example), but

    How to choose the CUSTID_x? that goes along with the winning Date?

    create table test_tbl)

    number of custid_1

    date of change_date_1,

    number of custid_2

    date of change_date_2,

    number of custid_3

    date of change_date_3,

    number of custid_4

    date of change_date_4,

    number of custid_5

    date of change_date_5

    );

    INSERT INTO test_tbl

    (CUSTID_1, CHANGE_DATE_1, CUSTID_2, CHANGE_DATE_2, CUSTID_3, CHANGE_DATE_3, CUSTID_4, CHANGE_DATE_4, CUSTID_5, CHANGE_DATE_5)

    VALUES

    (111, sysdate, 222, sysdate + 1, 333, sysdate + 2, 444, sysdate + 3, 555, sysdate + 4);

    commit;

    Hello

    Here's one way:

    WITH unpivoted_data AS

    (

    SELECT custid, change_date

    , EVALUATE () OVER (ORDER BY change_date DESC) AS r_num

    OF test_tbl

    UNPIVOT ((custid, change_date)

    Label ((custid_1, change_date_1) AS 1)

    , (custid_2, change_date_2) AS 2

    , (custid_3, change_date_3) AS 3

    , (custid_4, change_date_4) AS 4

    , (custid_5, change_date_5) AS 5

    )

    )

    )

    SELECT custid, change_date

    Of unpivoted_data

    WHERE r_num = 1

    ;

    Having several columns for several occurrences of basically the same thing is a bad table.  This problem would be much simpler, but also more effective if each pair custid/change_date has been strored on a separate line.  In addition, you would not be limited to 5 pairs.

  • remove the negative values in table

    I have a table 1 d of data depending on the positive and negative values. I'm trying to search for negative values and remove them from the table.  This corresponds to the data in the column in the second table 2D that should also be deleted. A minor problem is that there are an additional column in the 2D array that must be skipped.  I have the code that should do it.  The problem is that if I have two negative numbers in a row the code doesn't thow on the other.

    This first picture is the answer I get when alternate positive and negative values.  It shows the correct answer.

    When I change the first1 of the positive a-1 value as shown below...

    ... I get the following response.

    FYI, some other things such as conversion are here because I'm trying to manipulate the actual data set is enormous.  I test everything I do with the numbers that I can actually follow before I apply in my real program.  That's why I do extra things.

    Thanks for the help!

    Here is the solution, that increase the index when you do not remove an element. In addition, whether you use the "less then or equal" when you use the "lower to."

  • can we write the function in a select statement?

    I have function and there Out parameter, so in this case I can write a select statement to my function to retrieve the value?

    user11195165 wrote:
    I have function and there Out parameter, so in this case I can write a select statement to my function to retrieve the value?

    Never mind that it's bad! for a function to have an OUT parameter. That's not how the functions should be designed and written.

    It's like with a knife like a spoon to eat porridge. Of course, it can work in a way. But why? A knife was never designed to be a spoon - and while it may work of porridge to eat, you'll have a hell of a time trying to use it to eat the soup. So, use the right tool.

    In other words, a function is the wrong tool for the job. Use a procedure.

  • How can I include multiple SELECT statements in a PL/SQL?

    I want to be able to include multiple SELECT statements in a PL/SQL script. Here are 2 of my SELECT statements. They compile them and run successfully, but when I try to run them together, I get the error: ORA-06550: line 26, column1: PLS-00103: encountered the symbol "BEGIN." Line 26, it is where the 2nd script begins. Thank you in advance for your help!

    Set serveroutput on
    DECLARE
    v_item_type VARCHAR2 (20);
    number of v_total_count;
    v_approved VARCHAR2 (20);
    number of v_apprv_count;

    BEGIN
    SELECT ITEM_TYPE, count (*)
    IN v_item_type, v_total_count
    Of
    APPLSYS. WF_ITEMS
    WHERE
    ITEM_TYPE = "GLBATCH" AND
    End_date is not null
    ITEM_TYPE GROUP;
    dbms_output.put_line ('Item_type: ' | v_item_type);
    dbms_output.put_line ('Count: ' | v_total_count);
    END;

    BEGIN
    SELECT B.ACTIVITY_RESULT_CODE, COUNT (*)
    IN v_approved, v_apprv_count
    Of
    APPLSYS. WF_ITEMS, A.
    APPLSYS. B WF_ITEM_ACTIVITY_STATUSES,
    APPLSYS. FND_USER C.
    APPLSYS. FND_USER D
    WHERE
    A.ITEM_TYPE = B.ITEM_TYPE AND
    A.ITEM_KEY = B.ITEM_KEY AND
    A.ITEM_TYPE = "GLBATCH" AND
    A.END_DATE is not null AND
    A.OWNER_ROLE = C.USER_NAME and
    B.ACTIVITY_RESULT_CODE = "APPROVED" AND
    B.ASSIGNED_USER is not null and
    B.ASSIGNED_USER (+) = D.USER_NAME
    GROUP BY b.activity_result_code;
    dbms_output.put_line (' approved: ' | v_approved);
    dbms_output.put_line ('Count: ' | v_apprv_count);
    END;

    Try this,

    Declare
       v_item_type   Varchar2(20);
       v_total_count Number;
       v_approved    Varchar2(20);
       v_apprv_count Number;
    Begin
       -- First SQL
    
       SELECT ITEM_TYPE
             ,Count(*)
         INTO v_item_type
             ,v_total_count
         FROM APPLSYS.WF_ITEMS
        WHERE ITEM_TYPE = 'GLBATCH'
          AND END_DATE Is Not Null
        Group BY ITEM_TYPE;
    
       dbms_output.put_line('Item_type: ' || v_item_type);
       dbms_output.put_line('Count: ' || v_total_count);
    
       -- Second SQL
    
       SELECT B.ACTIVITY_RESULT_CODE
             ,Count(*)
         INTO v_approved
             ,v_apprv_count
         FROM APPLSYS.WF_ITEMS                  A
             ,APPLSYS.WF_ITEM_ACTIVITY_STATUSES B
             ,APPLSYS.FND_USER                  C
             ,APPLSYS.FND_USER                  D
        WHERE A.ITEM_TYPE = B.ITEM_TYPE
          AND A.ITEM_KEY = B.ITEM_KEY
          AND A.ITEM_TYPE = 'GLBATCH'
          AND A.END_DATE Is Not Null
          AND A.OWNER_ROLE = C.USER_NAME
          AND B.ACTIVITY_RESULT_CODE = 'APPROVED'
          AND B.ASSIGNED_USER Is Not Null
          AND B.ASSIGNED_USER(+) = D.USER_NAME
        Group BY b.activity_result_code;
    
       dbms_output.put_line('Approved: ' || v_approved);
       dbms_output.put_line('Count: ' || v_apprv_count);
    End;
    

    Hope this helps,
    Christian Balz

  • How can I do to two clips have the same position and scale?

    I just first Elements 10 today, since I'm doing a video for work. I am a seasoned videographer (I am a fairly successful YouTuber), but not with Adobe products. At home, I use Cyberlink PowerDirector 13 (although that is seriously considering moving to Premiere Pro), but for the moment at work I use elements since it is the program that they have.

    One thing that elements can do that PowerDirector is automatically align the clips at the same time. What I need to do, it's got a picture (do not fill the entire screen) suddenly cut to a similar picture of the same size and position, of the effect that the only part of the image changes. In my program to another, all I had to do was put them at the same time, change the shape of the Pic 1 how I want it, move the 2 Pic and do align on the same size and position, then move 2 peak after another in the timeline panel. However, items not the snap to each other, so I have no idea how to put them in the same size and position, one after the other.

    How can I do this? If this can be done in two elements or Pro, I'm going to have to Pro since I use this feature a lot.

    Thanks in advance!

    -Michael

    Michael

    First Elements 10 on what operating system? What video/graphics card your computer use? If NVIDIA GeForce, so we talk 10/NVIDIA GeForce display and other problems related specifically to first Elements.

    But, so far away that...

    Each clip on the Timeline of 10 elements first has a range of properties that contains a sign of movement. The expanded Motion Panel includes settings for the clip Position and scale. among other things.

    Position of two values... (___) (_) first from right to left and from left to right... second for up down or down the most.

    Have you been to the Palette of the 2nd clip properties to set its Position and scale values must match the first element?

    Have you been there and done that?

    Please read and review, and so let me know if I've targeted to what asked you. If this isn't the case, please specify where I missed what you were looking for.

    We'll rethink the situation if necessary and provide screenshots if necessary.

    Thank you.

    RTA

  • Negative value to run to analyze the report in the statspack report

    Hello

    I use Oracle 10.2.0.3.

    In the Execute to analyze the value of its pack stats report report, I get the negative value-35%. I read that this means that there are more number of parse as executions. But how and where it can be checked off, and what step I can take to resolve/correct this?

    I have a procedure 'a' who calls the procedure b, c and d in it.

    I have a table "t" that is referenced in the proceedings b, c and d (not in one)

    I've run a DDL on the table "t" where, by b, c and d invalid and in which cases invalidate the procedure as well.

    I call the procedure 'a' for execution, but in this procedure, I circumvent enforcement of procedures b, c and d (I can do this based on a condition and I don't call these procedures during execution of the procedure a).

    Then, when I call the procedure, it will be recompiled, but before he could be recompiled, oracle has recompile b, c and d as well.

    So in this case, I don't have that a single execution of procedure 'a' but compilation of a, b, c and d have run to analyze the ratio of 1:4.

    I hope you understand now. Which is why I suspect me that your procedures are be invalidated yet and still have several compilations.

    Salman

Maybe you are looking for

  • IOS El Capitan - computer crashes

    I have a 2007 iMac runs on OS X El Capitan and my computer freezes all the time. I checked all the discussions and found something but it was for IOS Mountain Lion. Does anyone has the same problem? Can someone help me please?

  • Toshiba virtual Store account Reset - 25065

    Please reset my account number of virtual shop 25065Thank you

  • Notification Server 2008 R2 errors

    There is always 2 errors appearing in the dashboard from the server. The first is the typical 'surveillance computer error' which, after having applied the Hot MS difficulty is still there, the second is an error message indicating a PC Backup throug

  • Put HP1012 in place. The installation process does not recognize the printer.

    I've made sure the device is on and the usb cable is connected.  Printer worked fine until I needed to reinstall the windows xp operating system.  Now reinstall the printer set up the software does not recognize the printer.  Before reinstalling the

  • The set of network configuration instructions to use for Officejet?

    Hello I have an Officejet K850 and it works on a Mac 10.6.8 System. I've never run this printer via the wireless network, but I would like to. There are a few pages in the user manual that explain this. But I also found this link on the HP site which