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 subnodesI 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)
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)
If you use subQuerys, the solution is below.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.
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 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 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 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
-
First Adobe has charged to me for the second month and I do not think its fair... How do I get my money back?
You know that when you purchase a subscription, you do not pay a month ago and you own the software?
You pay a subscription that you want to use Cloud Plans https://creative.adobe.com/plans software
Cancel see answer #1 in https://forums.adobe.com/thread/2023066 - includes a link to Chat from Monday to Friday
-
I look at the TB dashboard seen comes from open TB. On the left, I see folders. The folder "sent", lets say, is higher than the "Outbox" folder I want to put the "Outbox" folder above the folder "sent". How do I do this ever?
I know that the addon will allow you to rearrange accounts, so you could put 'Local folders' over another e-mail account.
It will also allow you to use files within an account.So if you have a Pop email account that uses the Global setting of the "Inbox", then it should allow you to move the position of the Outbox within this special account.
But as the 'Outbox' is a 'Local folder' folder, I'm not sure that you can move it out of "Local folders" and reposition it on another account.
The method for moving files is done via the menu bar.
'Tools' > 'manually sort folders ".
Select the folder and use "move up" or "Down" buttons.
Then click on the button "refresh folderpane' to see the new sort order. -
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.
-
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
-
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
-
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
-
Dynamic calc to calculate the sum of the months in the years
I have a 6.5.5 Essbase cube with a size of periods containing months and weeks as members stored, labeled as time. I also have a dimension of the year that contains exercises and these members can also be stored. I have to add together the first month of this year and the last month of last year.
I can do this:
M12-LY + M01-> TY >
Gives me the right answer and I could configure IF statements through Sunday to the correct value of LY, but I would like the formula dynamically select the correct LY based on the year TY that the user puts in place in their query. I tried some combos using @prior and @shift and it is not working properly.
Here is what I thought might work:
M01 + (@SHIFT (Year-1));
This formula results by adding just the M01 and nothing of LY. Any thoughts on how to configure this formula?
Published by: user11908498 on 16 Sep, 2009 05:55
Published by: user11908498 on September 16, 2009 11:42What your year Sun look like?
The support is that it looks like this
Year
-2008 (LY)
-2009 (TY)So if you're on TY, then shift - 1 (or before) it would go to the 2008 (LY)
By chance your year sun goes in the opposite direction
Year
-2009 (TY)
-2008 (LY)In this case, you will have to go the other way
"M01" + @SHIFT ("M12", 1, @CHILDREN ("Year"));
-
I installed Firefox 21 on a new Windows 7 operating system. The menu bar and the toolbar at the top of the windows is full small horizontal lines. Sometimes, there are more lines and sometimes less. It makes the icons and menu items almost impossible to see. So far, is that the Firefox screen that made it. Other programs I have installed so far doesn't do this.
Any ideas?
Try disabling hardware acceleration in Firefox.
- Tools > Options > advanced > General > Browsing: "use hardware acceleration when available.
- https://support.Mozilla.org/KB/troubleshooting+extensions+and+themes
Maybe you are looking for
-
Gray screen turns when I load my Satellite L300.
Hello For some time I am facing a problem with my toshiba satellite L300.Indeed, * when I charge my phone while I'm working, after 5 minutes maximum, the screen turns grey which prevent me from working while the laptop is in charge. However, in safe
-
A TV in my area [Melbourne-Australia] channel broadcasts Teletext.When I got my G20 with MCE 2005 it worked very well.At some point, everything goes wrong and now all I get is a black screen, about half the size of the laptop screen on the top of thi
-
How to deal with "Outlook" pst files
Hi guys, just a message quicky, for various reasons in recent weeks I have had problems with my Microsoft Outlook, which I use for e-mail, etc.. I have created a number of .pst files and would like some advice as to how best to group them into a sing
-
Cannot install Windows Home Server
Every time I have try and install windows home server it goes through the windows of files loading screen, then green bars on a loading screen then nothing. Let it sit overnight and still nothing Running an IBM thinkcentre with a Pentium 4 processor
-
Printers HP 6520: 6520 cartridge door lock
Print quality spoils before the ink level says cartridge is empty. Want to know how to unlock door cartridge manually so that I can change the low ink cartridges. Forums online with HP Tech answers don't address this issue. Nothing in the printer mau