Calculate the sum of values of 2 where Clauses
Hi, sorry to trouble, I have all the data in a database or anything like that, just to think about some of the work I have to do, trying to get ahead. I was wondering how i would be the sum of the values in a column, but with 2 where clauses. By example, if I wanted to the sum of all the values until 18:00 in 1 column and all the after 18:00 for 1 day how I would write this out.
I don't know how to write separately, i.e.
select name, sum(values) as after6 from table where time > '18:00' group by name;
select name, sum(values) as upto6 from table where time < '18:00' group by name;
How can I combine these columns after6 and upto6 next to each other.
If someone could please advise.
Thanks in advance
Select the name,
sum (case when time > 18:00 ' then 0 otherwise end of values) as after6,.
sum (case when time< '18:00'="" then="" values="" else="" 0="" end)="" as="">
table
Group by name;
----
Ramin Hashimzade
Tags: Database
Similar Questions
-
How to calculate the sum of the fields to fill?
Hello!
My question is how can I calculate the sum of filled areas?
For example, in a PDF document, I have a few fields that must be filled out with name and surname and the end of the document, another field that is the sum of the fields "FullName" which shows how many people is in this document. The operation should not take into account white/empty areas.
Now, I know that I could do with the simple calculation "(+) sum" but I have to put a '1' for each of this area and I would like to avoid this.
Yes, it's the first option I described. In this case, you can use this code:
var total = 0; for (var i=1; i<=79; i++) { if (this.getField("Nume si prenume "+i).valueAsString!="") total++; } event.value = total;
-
How to calculate the sum of two digital form fields based on the selection of the checkbox.
I have a form in Acrobat Pro who needs a custom calculation. How to calculate the sum of two digital form fields based on a selection of the checkbox. I have three number fields. Field-A and B are simple one or two digits. Field-C is the sum, or the total field. I want to field-C have a control box which, when turned on and off, just gives a. gives the sum of A + B
_ Field - 2
_ Field - A 4
[check] _ _ field - 6 C
[disabled] _ _ field - 2 C
Thank you
The custom field C calculation script could be:
(function () { // Get the values of the text fields, as numbers var v1 = +getField("A").value; var v2 = +getField("B").value; // Set this field's value based on the state of the check box named "CB" if (getField("CB").value !== "Off") { event.value = v1 + v2; } else { event.value = v1; } })();
Replace 'A', 'B', and 'CB' with the real names of the fields.
-
CALCULATE the sum of the amounts?
Hey guys!
This script:
produces this result:CLEAR COMPUTES CLEAR BREAKS SET feedback off SET pagesize 5000 SET linesize 50 SET echo off SET heading on SET verify off COLUMN User format A8 COLUMN Files format 999999999 COLUMN Docs format 999999999 COLUMN Pages format 999999999 COMPUTE SUM LABEL TOTAL OF "FILES", "DOCS", "PAGES" PROMPT ************************************************** PROMPT * Monthly File Activity by User * PROMPT ************************************************** PROMPT PROMPT ACCEPT StartDate DATE FORMAT 'MMYYYY' PROMPT 'Enter the month and year (MMYYYY): ' PROMPT PROMPT List of users: PROMPT One PROMPT Two PROMPT Three PROMPT Four PROMPT Five PROMPT Six PROMPT Seven PROMPT UNKNOWN PROMPT PROMPT Type 'ALL', or leave blank, to select all users. PROMPT ACCEPT UserChoice DEFAULT 'ALL' PROMPT 'Please enter a user: ' SELECT (CREATOR_ID WHEN '1' THEN 'One' WHEN '2' THEN 'Two' WHEN '3' THEN 'Three' WHEN '4' THEN 'Four' WHEN '5' THEN 'Five' WHEN '6' THEN 'Six' WHEN '7' THEN 'Seven' ELSE 'UNKNOWN' END) "USER", count (distinct(substr(DOC_NAME,1,9))) AS Files, count (DOC_IMAGE) AS Docs, sum (DOC_PAGE) AS Pages FROM TABLE1, TABLE2 WHERE DOC_DATE to_date('&StartDate','MMYYYY') AND last_day(to_date('&StartDate','MMYYYY')) AND CREATOR_ID not in ('Thing','8','9') AND ((CREATOR_ID WHEN '1' THEN 'One' WHEN '2' THEN 'Two' WHEN '3' THEN 'Three' WHEN '4' THEN 'Four' WHEN '5' THEN 'Five' WHEN '6' THEN 'Six' WHEN '7' THEN 'Seven' ELSE 'UNKNOWN' END) = UPPER('&UserChoice') OR '&UserChoice' = 'ALL') GROUP BY CREATOR_ID /
I would like for a labeled sum TOTAL at the bottom of these figures. I thought that COMPUTE would take care of this, but it's not. Am I missing something? It will not add these to the top because they are already money from specific users? Insight? I'm new to SQL and would like to be pointed in the right direction. Thanks for your expertise!USER FILES DOCS PAGES -------- ---------- ---------- ---------- One 261 4276 18124 Two 364 5954 26913 Three 109 1996 8243 Four 178 3635 14554 Five 104 2657 11662 Six 308 6639 27887
I'm on a 10g system.Calculation is not SQL and SQL * more.
The general syntax is
calculate the sum of... the* | * report followed by
break the report
When this is necessary.-----------
Sybrand Bakker
Senior Oracle DBA -
Calculate the sum of the columns
Hello!
Am using jdeveloper 11.1.2.1
I created a table VO based EO. I need to calculate the sum of the column named price.
I use the expression PoView.sum ("Price"). In this PoView is the name of VO and the price is the name of the column.
While spin AMModule I got an exception like
PoView name not found in the given object.Hello
You must use the name accessor EO or VO instead of the name of VO.
See https://blogs.oracle.com/adf/entry/using_groovy_aggregate_functions_in (there are even the same error message in one of the comments of this blog)concerning
Peter -
calculate the sum of the two columns - display the result in the third column
Hello
I have a report and I want to calculate the sum of the two columns of the report and display the total in the third column.
For example: Sample_My_Report
Col1 Col2 (Col1 and Col2) Total
3-7-10
can someone help me with this question.
Thank you.Hello:
If your report is an IR you can use the menu "Tool" to add columns calculated at the State
CITY
-
How to calculate the sum of the values of some columns in a table
Hello
I want to get the column just the average of the values of some columns not all columns of the table.what I have to change exactly in this block diagram.even if the table size is 25 average, I want the division as the number of values in each column (= number of lines)
just like that:
-
Calculate the sum of the duration stored in format HH24
Dear professionals,
I use Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production. I stored length of certain events in the table TIME_DURATION as as follows (format h24:mi):
CREATE TABLE "TIME_DURATION" ("ID" NUMBER(11,0), "HOURSMINUTES" VARCHAR2(5)); Insert into TIME_DURATION (ID,HOURSMINUTES) values ('5','00:55'); Insert into TIME_DURATION (ID,HOURSMINUTES) values ('7','00:18'); Insert into TIME_DURATION (ID,HOURSMINUTES) values ('9','06:34'); Insert into TIME_DURATION (ID,HOURSMINUTES) values ('15','00:12'); Insert into TIME_DURATION (ID,HOURSMINUTES) values ('17','09:50'); INSERT INTO TIME_DURATION (ID,HOURSMINUTES) VALUES ('41','12:39');
select * from time_duration; ID HOURS ---------- ----- 5 00:55 7 00:18 9 06:34 15 00:12 17 09:50 41 12:39 6 rows selected.
Now, I want to calculate the total time for all events (sum of all specific times). In this case, it should be 30 hours and 38 minutes.
Any help would be much appreciated.
Thanks in advance.
Hello
So, you want to add a number of lines varibale. This sounds like a job for the SUM function. AMOUNT of work on numbers, no channels such as time, so use TO_NUMBER to convert strings to numbers, so you can add them. If you want to display the result as a string, you can use TO_CHAR to convert the sum into a string.
WITH got_total_minutes AS
(
SELECT SUM ((TO_NUMBER (SUBSTR (heure, 1, 2) * 60)))
+ TO_NUMBER (SUBSTR (hour 4))
) AS total_minutes
OF time_duration
)
SELECT TRUNC (total_minutes / 60). ':'
|| To_char (MOD (total_minutes, 60))
, "FM00.
) AS total_hours_minutes
OF got_total_minutes
;
The output is not quite what you asked:
TOTAL_HOURS_MINUTES
--------------------
30: 28
If you really want 30:38', explain how to get it.
This solution assumes that time always is always 5 characters (2 digits, a separator and another of 2 digits) as it is in your sample data.
If your actual data aren't like your sample data, the same approach still works, but the SUBSTR expressions will be more complicated.
adnanBIH wrote:
Dear professionals,
I use Oracle Database 11 g Enterprise Edition Release 11.2.0.4.0 - 64 bit Production. I stored length of certain events in the table TIME_DURATION as as follows (format h24:mi):
- CREATE TABLE 'TIME_DURATION' ('ID' NUMBER (11.0), VARCHAR2 (5)) 'HOUR '.
- Insert into TIME_DURATION (ID, TIME) values ('5',' 00:55 ');
- Insert into TIME_DURATION (ID, TIME) values ('7',' 00:18 ');
- ...
Thanks for posting the CREATE TABLE and INSERT.
ID is a NUMBER, so do not use quotes around it:
Insert into TIME_DURATION (ID, TIME) values (5, ' 00:55 ');
Insert into TIME_DURATION (ID, TIME) values (7, ' 00:18 ');
...
Depending on how you plan to use the hour, you may want to store a NUMBER, also, or maybe an INTERVAL DAY TO SECOND.
-
Calculate the sum involved new VO
Gurus,
I want to have a sum of column values in a table. I looked at a number of post on OTN, but it does not work
Created a transitional attribute in the VO. expression and passed to the next value
also triedVO.getRowSet().sum("((Mtd == null) ? 0 : Mtd)
andadf.object.getRowSet().sum("((Mtd == null) ? 0 : Mtd)
MTD is the column in the original Version I want to calculate the totalobject.getRowSet().sum("((Mtd == null) ? 0 : Mtd)
Can you please advice what's not here
thnks
Published by: in the line of fire on August 10, 2011 10:46I've tried this so 11.1.1.4, not 11.1.1.5 but it should work.
You can keep the condition in the expression:
object.getRowSet (.sum) (' bat == null? 0: Mtd')
to make sure that you have no problem with null values.Apart from this, make sure that everything is in the type of data in the database and the VO.
Gabriel.
-
How to calculate the sum (discount) when check box status = 'Y '.
Hai.
It's Vinet I want sum (disc) of particular elements check box STATUS = 'Y'
I selected the quota_det TABLE data
I have 5 codes elements
SNO Agenda ITEMCODE QTY. BASIC PRICE DIS_PER DISK STATUS
1 DELL 2 30000 60000 5 57000 D26OO Y
2 HP HP2300 1 20000 20000 2 19600 N
3 SAMSUNG SM560 2 5300 10600 3 10282 N
4 NOKIA 5 25600 128000 3 125440 NK63 Y
5 HTC 1 2300 2300 2 2254 HT25 Y
ALL ARE ELEMENTS of DATABASE BUT STATUS IS NOT a basic ELEMENT of DATA THAT IS the POINT of the BOX
VALUE CHECK = Y
A VALUE WHEN UNCHECK = N
IN above DATA I WANT ONLY ELEMENTS SUM (DISC) WHEN the POINT of the BOX CHECK THAT the SUM SHOULD BE APPEAR IN TOT_VALUE * POINT *.
SEND ABOVE CODE REQUIREMENT WITH THE NAMES OF TRIGGER ITS URGENT...
Published by: 988532 on March 22, 2013 22:27Hi Vincent!
You can try this!
Make another text point something as a disc_copy between the disc and on the same block
below this text element properties
1 piece of data: No.
2. data type: number
3 canvas: NullCreate another element of text like total_discount below the properties
1 piece of data: No.
2. data type: number
3 method of calculation: summary
4. function: sum
5. block of summaries: YourBlock
6 point summaries: disc_copyIf you are multi block record is then
7. number of items: 1Set property YourBlock
All records in the query: YesNow, about the situation to apply trigger WHEN-CHECK-BOX-CHANGED and write below the code in this trigger
if :YourBlock.status='Y' then :YourBlock.disc_copy:=:YourBlock.disc; else :YourBlock.disc_copy:=0; end if;
Published by: XeM on 23 March 2013 12:06 AM
Published by: XeM on 23 March 2013 12:07 AM
-
Calculates the treatment field values 1 step behind
I have a very long form created in Acrobat Pro (latest version).
To simplify the problem, this is what is happening.
I have text boxes on a form and the user will enter quantity and price in each row for the materials and form will calculate to multiply these values and give you the total for each product and at the end, add all the totals giving you your total final.
T1 * P1 = T1
T1 + T2... T40 plus Total cost of material
Which works very well.
I then the user enter the estimate and below this breakthrough for what is the cost of labour, which is the cost of equipment, which is taxes, and then the rest is profit. The cost of the equipment is simply copied to the Total cost of the above materials.
However, the calculation is made to simply take so I need percentages thus:
The total cost of materials / estimate = percentage
This grave 1 step walk behind. As in, it has not calculated the first go-around. You must enter a value elsewhere on the form or if I generate a button "Calculate" it will then deal with it. It's like if we take the old value before the field has been dynamically updated.
Link to the PDF is below, if you fill in the Qs and Ps see the Ts fill fine.
Below on the left turns is the estimate that you need to enter. In doing so, you will see the % for material cost and profit are bad, if you change a value anywhere on the form, you will see that they are then the value that was already there.
I hope that makes sense for a person, the calculated values are 1 step behind and I need to understand why and get that fixed.
Also, if I do these fields % under the shape number and 2 decimal places, I get an avalanche of mistakes whenever I enter a new value somewhere on the form I think because he's trying to divide by a number of vacuum which get a NaN error and gives me a pop up that it does not match the required format. How can I disable this error? I need to limit it to 2 decimal places, or 3 actually, but don't have a ton of errors popup whenever the user starts to fill the form.
It's a problem of calculation of classic field command. You need to go to Tools - Forms - change - other tasks - defined field calculation order and whole list in the order in which calculations occur. So if a field is dependent on the value of the field B, then it must be lower than him in the list.
-
To calculate the sum Vals and LV is higher than its target line LV
When I answered this thread of application of the hierarchy and the number of subnodes
I made this question.
I use Oracle11gR2.
I want the sum Vals and LV is superior to his LV of the target line to the command by sorkKey.
Ex if LV 2, sumVal is the sum of this line and another line which LV > 2.
MyTable sortKey LV Val ------- -- --- 1 2 10 3 3 20 5 4 30 6 3 40 7 4 50 9 2 60 15 3 70 16 4 80
with MyTable(sortKey,LV,Val) as( select 1,2,10 from dual union select 3,3,20 from dual union select 5,4,30 from dual union select 6,3,40 from dual union select 7,4,50 from dual union select 9,2,60 from dual union select 15,3,70 from dual union select 16,4,80 from dual)
If you use subQuerys, the solution is below.expected Output sortKey LV Val sumVal ------- -- --- ------ 1 2 10 150 (10+20+30+40+50) 3 3 20 50 (20+30) 5 4 30 30 (30) 6 3 40 90 (40+50) 7 4 50 50 (50) 9 2 60 210 (60+70+80) 15 3 70 150 (70+80) 16 4 80 80 (80)
But it's very complex :-(
My question is "is it more simple solution?
For ex using fuction OLAP, model clause etc...
with MyTable(sortKey,LV,Val) as( select 1,2,10 from dual union select 3,3,20 from dual union select 5,4,30 from dual union select 6,3,40 from dual union select 7,4,50 from dual union select 9,2,60 from dual union select 15,3,70 from dual union select 16,4,80 from dual) select sortKey,LV,Val, (select sum(b.Val) from MyTable b where a.sortKey <= b.sortKey and b.sortKey < (select nvl(min(c.sortKey),99999) from MyTable c where c.sortKey > a.sortKey and c.LV <= a.LV)) as sumVal from MyTable a;
In fact, it can be simpler:
with t as ( select 1 sortkey,2 lv,10 val from dual union all select 3,3,20 from dual union all select 5,4,30 from dual union all select 6,3,40 from dual union all select 7,4,50 from dual union all select 9,2,60 from dual union all select 15,3,70 from dual union all select 16,4,80 from dual ) select sortkey, lv, val, sum(val) over(order by sortkey range between current row and rng following) sumval from ( select sortkey, lv, val, nvl( (select min(b.sortkey) from t b where b.sortkey > a.sortkey and b.lv <= a.lv) - a.sortkey - 1, max(sortkey) over() - a.sortkey ) rng from t a ) order by sortkey / SORTKEY LV VAL SUMVAL ---------- ---------- ---------- ---------- 1 2 10 150 3 3 20 50 5 4 30 30 6 3 40 90 7 4 50 50 9 2 60 210 15 3 70 150 16 4 80 80 8 rows selected. SQL>
SY.
-
to calculate the sum...
Hi all
I have table as A B C D I want to create a new liike table this A B C D E
1 2 x 1 2 1 x 1 x 20
2 3 x 2 x 3 2 x 2 x 20
3 4 x 3 x 3 4 x 3 x 20
5 6 y1 y1 YY 5 6 96
7 8 y2 y2 YY 7 8 96
I am writing my syntax like this
SELECT a, b, c, d, SUM(a*b) AS f FROM xyz GROUP BY d, a, b, c;
I get only product of A and B, but I still want the sum OF THE PRODUCTS accordingly with D...
Please correct where I am doing wrong...
Thank you
Mike1 with x as ( 2 select 1 a, 2 b, 'x1' c, 'x' d from dual 3 union all 4 select 2, 3, 'x2', 'x' from dual 5 union all 6 select 4, 5, 'x3', 'x' from dual 7 union all 8 select 6, 7, 'y1', 'y' from dual 9 union all 10 select 8, 9, 'y2', 'y' from dual 11 ) 12 select a, b, c, d, 13 sum( a*b ) over (partition by d) e 14* from x SQL> / A B C D E ---------- ---------- -- - ---------- 1 2 x1 x 28 2 3 x2 x 28 4 5 x3 x 28 6 7 y1 y 114 8 9 y2 y 114
Justin
-
Calculate the distance using values from table
Based on the coordinates of two points A(x1,y1) and B(x2,y2) and x 1, x 2, y1, y2 are columns of the table to a table, I need a query (function?) to calculate the distance between these two points of each line of the table...
Table:
NRCRT (PK) X 1 X 2 Y1 Y2
1 10 6 2 4
2 1 3 0 5
the mathematical formula is:
http://www.mathwarehouse.com/algebra/distance_formula/images/distance-formula-image.jpg
It is complex to me, but maybe someone can help me...Wintermute3190 wrote:
Œuvres, but:
DISTANCE_BETWEEN
4.47213595499957939281834733746255247088
5.3851648071345040312507104915403295563How to set to 5,38 just and 4.47
CYCLE of use or function TRUNC
SQL> WITH test_tab AS 2 (SELECT 1 nrcrt, 10 x1, 6 x2, 2 y1, 4 y2 3 FROM DUAL 4 UNION ALL 5 SELECT 2, 1, 3, 0, 5 6 FROM DUAL) 7 SELECT nrcrt, 8 TRUNC(SQRT ((POWER ((x2 - x1), 2) + POWER ((y2 - y1), 2) 9 )),2) distance_between 10 FROM test_tab 11 / NRCRT DISTANCE_BETWEEN ---------- ---------------- 1 4.47 2 5.38 SQL> WITH test_tab AS 2 (SELECT 1 nrcrt, 10 x1, 6 x2, 2 y1, 4 y2 3 FROM DUAL 4 UNION ALL 5 SELECT 2, 1, 3, 0, 5 6 FROM DUAL) 7 SELECT nrcrt, 8 ROUND(SQRT ((POWER ((x2 - x1), 2) + POWER ((y2 - y1), 2) 9 )),2) distance_between 10 FROM test_tab 11 / NRCRT DISTANCE_BETWEEN ---------- ---------------- 1 4.47 2 5.39
Notice the difference in the result. Use the one that works best for you.
Kind regards
JO -
Version of DB: database Oracle 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production
I have a table my_table as below:
create table my_table
(
my_code varchar2 (6).
my_id varchar2 (24).
forced pk_1 primary key (my_code, my_id)
);
Primary_key here's a composite key that contains columns 1 (my_code) and 2 (my_id).
Is there that a difference in the way below queries is executed in terms of performance (use of indexing in the extraction).(a) select * from my_table where my_code = '123' and my_id = "456";
(b) select * from my_table where my_id = '456' and my_code = '123';
The understanding I have the order of the column in the where clause should be identical to the sequence in
What primary key draws for indexing to be used by oracle in oracle other DML queries ignores indexing
However when I used explain plain both show the same query cost with single scan with index rowid.
so I don't know if I'm wrong in the concept that I have. Kindly help.Thanks in advance,
GerardYour question is answered in the Performance Tuning Guide
14.1.4 choosing composite indexes
A composite index contains several key columns. Composite indexes can provide additional benefits compared to the index to single column:
- Improved selectivity
Sometimes the two or more columns or expressions, each with a low selectivity can be combined to form a composite with a high selectivity.
- Reduced IO
If all columns selected by a query are a composite index, then Oracle may return these values in the index without access to the table.
A SQL statement can use a path on a composite index if the statement contains constructions that use a main part of the index.
Note:
This is no longer the case with the skip index scans. See "Index Skip Scans".
A main part of an index is a set of one or more columns that have been specified first and consecutively in the list of columns in the
CREATE
INDEX
statement that created the index. - Improved selectivity
Maybe you are looking for
-
How can you fix an iPod that won't boot to the top or either load I went to a local store to see if it can charge, but it cannot and it is running ios 9.3.3 32 g
-
How can I disable the popup to address link at the bottom of the page?
I don't want links to appear in the small window at the bottom of the page. I used the solution here https://support.mozilla.org/en-US/questions/822487#answer-184316 but since Firefox 25.0 this annoying popup appears again.
-
I have a computer that I have a problem with setting... It is an all-in-one PC 20-2000 a When it is turned on the fan turns and the only sign of life is the light of flashing card reader The research I found that a few HP desktop computers had this p
-
Hello I have a Pavilion dv6870ee that I bought a year ago, I have a problem with the battery life because my battery lasts only an hour or two even if I have a program (Mozilla Firefox) running. I don't know if it's a battery or computer failure. I w
-
I have a Toshba Satellite. I think, it's my dad's old computer.I'm trying to use Skype, oovoo, and yahoo with the webcam and a message said "sorry, no Webcam has found on your system. I have no idea how to install on. The computer has one on the scre