sum of column
HelloCan someone show me the best query to get the below output
The code I used to read me the below one, but I am confused on how to get the total general.
select grade,sum(losal)lowsal,sum(hisal)hisal,sum(losal+hisal)as total from SALGRADE
group by grade
OUTPUT-LOWSAL OF THE CATEGORY WILL DESIGNATE TOTAL
1 1000 2422 3422
2 1801 2490 4291
4 2001 3000 5001
5, 3001, 9999, 13000
3 1401 2000 3401
TOTAL OF THE COLUMN "TOTAL".
CREATE TABLE SALGRADE
(
NUMBER OF GRADE,
NUMBER OF IT,
NUMBER OF DESIGNATE
)
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
1, 300, 1222).
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
2, 300, 545);
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
1, 700, 1200);
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
2, 1201, 1400);
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
3, 1401, 2000);
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
4, 2001, 3000);
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
5, 3001, 9999);
INSERT INTO SALGRADE (GRADE, IT, WILL DESIGNATE) VALUES)
2, 300, 545);
COMMIT;
Thank you
Published by: GIRIKAIMAL on May 11, 2012 09:58
Published by: GIRIKAIMAL on May 11, 2012 09:59
Total general for all columns:
select grade,
sum(losal) lowsal,
sum(hisal) hisal,
sum(losal+hisal) total
from salgrade
group by grouping sets((),(grade))
order by grade nulls last
/
GRADE LOWSAL HISAL TOTAL
---------- ---------- ---------- ----------
1 1700 3622 5322
2 3002 3890 6892
3 2802 4000 6802
4 4002 6000 10002
5 6002 19998 26000
17508 37510 55018
6 rows selected.
Total general just for the total column:
select grade,
sign(grade) * sum(losal) lowsal,
sign(grade) * sum(hisal) hisal,
sum(losal+hisal) total
from salgrade
group by grouping sets((),(grade))
order by grade nulls last
/
GRADE LOWSAL HISAL TOTAL
---------- ---------- ---------- ----------
1 1700 3622 5322
2 3002 3890 6892
3 2802 4000 6802
4 4002 6000 10002
5 6002 19998 26000
55018
6 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
I have the table of 3 columns A, B, C. I want to store the sum of columns A B in the C column without using the DML statements. Can anyone help please how to do. ?
11.1 and especially you have virtual column
SQL> create table t 2 ( 3 a number 4 , b number 5 , c generated always as (a+b) virtual 6 ); Table created. SQL> insert into t (a, b) values (1, 2); 1 row created. SQL> select * from t; A B C ---------- ---------- ---------- 1 2 3
Before that, a front insert - trigger
SQL> create table t 2 ( 3 a number 4 , b number 5 , c number 6 ); Table created. SQL> create or replace trigger t_default before insert on t for each row 2 begin 3 :new.c := :new.a+:new.b; 4 end; 5 / Trigger created. SQL> insert into t (a, b) values (1, 2); 1 row created. SQL> select * from t; A B C ---------- ---------- ---------- 1 2 3
-
The Master Table column updated based on the sum of column Table detail
With the help of JDev 11.1.1.6.I have a master-detail table based on a link to BC.
The main table has a column that displays an InputText or an OutputText, based on the value in another column.
If the InputText is displayed, the user can enter a value and the database will be updated with that value.
If the OutputText is displayed, it must be a sum of a column in the secondary table. Also, this value will be written in the database.
Question:
How can I fill the OutputText in the main table with the sum of the values in a column in the secondary table?
The detail table column is a manually entered InputText field.
Thank you.
Create a spike in the main table and write in its expression as follows - DetailVoAccessorName.sum ("ColumnName");
This will calculate the sum of column table detail and then you can set the value of the transient attribute to attribute DB on backup operation
Ashish
-
Dear members,
Suppose I have a command name table and this table has 3 columns by name order_number, travel and net_weight.
The data are as follows:
Of the above, you can see that there are 2 lines, I need to write a SQL in such a way that my data should like below:Trip order# net_weight ---------------------------------------------------- 1876 1234 450 1876 5678 300 7865 6783 250 7865 9738 350
The new sum of column is the sum of net_weight based on the trip.Trip order# net_weight sum ------------------------------------------------------ 1876 1234 450 750 1876 5678 300 750 7865 6783 250 600 7865 9738 350 600
sum = 750-> (450 + 300 based on trip 1876)
sum = 600-> (250 + 350 based on trip 7865)
How can I write a SQL query to get the data as described above.
Thank you
SandeepUse analytical SUM:
with t as ( select 1876 trip,1234 order#,450 net_weight from dual union all select 1876,5678,300 from dual union all select 7865,6783,250 from dual union all select 7865,9738,350 from dual ) -- end of on-the-fly data sample select trip, order#, net_weight, sum(net_weight) over(partition by trip) total_net_weight from t order by trip / TRIP ORDER# NET_WEIGHT TOTAL_NET_WEIGHT ---------- ---------- ---------- ---------------- 1876 1234 450 750 1876 5678 300 750 7865 6783 250 600 7865 9738 350 600 SQL>
SY.
-
sum of column that contains the values in the time format
Hi all
I give you a piece of my code below
kindly helpSELECT dif.EMPLOYEE_NUMBER Employee#, dif.FULL_name EmployeeName, TO_CHAR(START_DATE,'dd-Mon-rrrr') DOJ ,dif.DEPT_NAME,POSITION , DATE_ENTRAY AttendanceDate, to_char(DATE_ENTRAY,'DY') day, TO_CHAR(LNE1,'hh24:mi')TimeIn1 ,TO_CHAR(LNE2,'hh24:mi')TimeOut1, TO_CHAR(LNE3,'hh24:mi')TimeIn2 ,TO_CHAR(LNE4,'hh24:mi')TimeOut2, TO_CHAR(LNE5,'hh24:mi')TimeIn3 , TO_CHAR(LNE6,'hh24:mi')TimeOut3, to_char(decode(LNE8,null , decode(LNE7,null, decode(LNE6,null, decode(LNE5,null, decode(LNE4,null, decode(LNE3,null, decode(LNE2,null,LNE2 ,LNE2 ),LNE3 ),LNE4 ),LNE5 ),LNE6 ),LNE7 ),LNE8 ),'hh24:mi')TimeOuts , ACT_HOUR Work_Hrs, decode(DLY_ABSENT_TYPE,'Late',DED_ABS ,'Late (Deduction)',DED_ABS,'00:00') Late_Hrs,ACT_OVT Over_Time FROM jjj_PUNCH_DATA_EMP_LIST trn , jjj_emp_def dif,jjj_PUNCH_CARD_ELEG ele WHERE trn.EMPLOYEE_NUMBER =dif.EMPLOYEE_NUMBER and ele.EMPLOYEE_NUMBER =trn.EMPLOYEE_NUMBER and DATE_ENTRAY between '23-Aug-2009' and '24-Aug-2009' I require to find the sum of column wrk_hrs Act_hour or wrk_hrs belongs to table jjj_PUNCH_DATA_EMP_LIST trn , and the datatype of act_hour is varchar(10 byte) the values of column act_hrs, (i require the sum of this column) 08:00 07:22 06:08
thanking in advance
concerning
Oracle userHello
Thanks for posting the CREATE TABLE and INSERT. That really helps.
Do you want 19:33 ' as the output? Which makes it look like 19 hours and 33 minutes. Most people would represent 19.33 hours (i.e. 19 more than 1/3 hours) as 19:20 '. Should not the sum of
' x: 00 ' and
'y: 20' be
"z: 20?If you really want 19:33 ', see the solution of Hoek.
If you really want 19:20 ', then you were on the right track.
I think that you were trying to do:WITH got_total_hours AS ( SELECT SUM ( TO_NUMBER (SUBSTR (act_hour, 1, 2)) + ( TO_NUMBER (SUBSTR (act_hour, 4, 2)) / 60 ) ) AS total_hours from p ) SELECT TO_CHAR (FLOOR (total_hours)) || ':' || TO_CHAR ( MOD (total_hours, 1) * 60 , 'fm00' ) AS hh_mm FROM got_total_hours ;
Looks like you were trying calculate total_hours in a subquery, then use the total_hour alias in a query Super, which is quite accurate. You're just confused on how to write a subquery.
There are two basic ways to write subqueries:
(1) WITH clause:
WITH sub_query AS ( SELECT ... ) SELECT ... FROM sub_query ;
(2) online review
SELECT ... FROM ( -- Begin sub_query SELECT ... ) -- End sub-query ;
Looks like you tried a bit of each method.
In most cases (this included problem) either one will work.
Other problems are much easier by using a WITH clause and WITH clauses are usually easier to read and understand, I recommend that you always use a WITH clause rather than views online.You can also change the Hoek solution to get the result 19:20 ' without a subquery (or without using any expression complicated, more than once, which is the only reason why I have proposed a subquery). Since date arithmetic Oracle comes from the days, not hours, when the solution of Hoek has calculated the number of hours, you'll have to divide by 24 to get the number of days. If you are using TO_CHAR to fit the time, however, the results can be confusing if the total is 24 hours or more. You might be better off using NUMTODSINTERVAL.
-
SUM OF COLUMN IN A TABLE.
How can I make the sum of the rows in a table in the apex oracle 4.2.6.
I want to perform validations on adj_amount column in a table. If the adj_amount column for the selected row is < = 0 then return false.
How can I choose the name of the column of tabular presentation in validation.
Hi Maxence,
CORINE wrote:
How can I make the sum of the rows in a table in the apex oracle 4.2.6.
I want to perform validations on adj_amount column in a table. If the adj_amount column for the selected row is<=0 then="" return="">=0>
How can I choose the name of the column of tabular presentation in validation.
Always provide the necessary information on your question.
Members of the Forum cannot determine information such as the type of tabular presentation, you use (i.e. Assistant generated/manual based on APEX_ITEM).
Now, the information you have provided, I concluded you want proof on a certain column the sum of this column must be greater than zero.
Well, you can use a "PLSQL function return Boolean" type, the level of the Page using APEX_APPLICATION validation. G_FXX berries.
Determine a column which is not null loop through this column and the adj_amount of the amount column. Determine if the sum is greater than zero and therefore trigger the validation.
Validation sample code would be:
DECLARE L_ADJ_AMOUNT_SUM NUMBER := 0; BEGIN FOR I in 1 .. APEX_APPLICATION.G_F01.COUNT LOOP L_ADJ_AMOUNT_SUM := L_ADJ_AMOUNT_SUM + TO_NUMBER(NVL(APEX_APPLICATION.G_F02(I),0)); END LOOP; IF L_ADJ_AMOUNT_SUM <= 0 THEN RETURN FALSE; ELSE RETURN TRUE; END IF; END;
Here APEX_APPLICATION. G_F01 is a column not null and APEX_APPLICATION. G_F02's adj_amount column for example.
NOTE: You can use a code inspection tools in the browser to identify to which column is mapped to APEX_APPLICATION. Table G_FXX.
Just inspect element in the column to determine the name attribute. If name = "f04" then it is mapped to APEX_APPLICATION. G_F04.
I hope this helps!
Kind regards
Kiran
-
Sum of columns together in the responses, and then calculated off summary columns
I have three questions answers (with 4 columns) that I have gathered the results for:
Four columns are: campaign # promoted # Respones, # Respones promoted
Query 1:
Campaign, # promoted, 0, 0
Query 2:
Campaign responses #, 0, 0,.
Query 3:
Campaign, 0, 0, # promoted Respones
My query returns the following (assuming that the campaign code is ABC) 3 rows:
Campaign of # Promoted # Responses # Promoted answers ABC 100 0 0 ABC 0 12 0 ABC 0 0 9 I want to put in place so that it adds campaign to get a row of results as follows:
Campaign of # Promoted # Responses # Promoted answers ABC 100 12 9 I can get this result using the conversion to a PivotTable (won't go thought road if possible because I have other calculations that I need to add). Once I get this summary to a single row result I then do a few such analyses that create:
- Response % (Respones # / # promoted)
- Promoted to the rank of % (# promoted answers / # promoted)
When I add the calculatinos to the percentages to the United query I get null or zero for my results. I used the Add button to insert a calcuation and then I used the following formula: saw_2 / saw_3
Here's what I would preferably:
- Sum of answers (not a pivot table) Table columns.
- Add columns calculated at United query that will produce results based on the combined pivot columns
- If I use the PivotTable, and then how to get the values calculated for work
Thank you...
Ben,
Try to use the rule of aggregation on the columns in the Table view and see if that makes a difference.
I just tried this and the SUM of each of the criteria provided the results I wanted, which in turn you are looking for.
If nothing works for you send me the screenshot of what you are trying to do at vijaybez at gmail and I can understand what is happening properly...
-
Hi friends
I use the Oracle 10 g with windows server 2008 Server. How to recover the sum of values of different column based on different conditions
Name of the table - stv_dtls
inv_type varchar2 (5)
credit number (12,2)
Case number (12,2)
name of the column - inv_type - four type of values - type1, type2, type3, null (empty column)
I want to make the sum of the column of credit under the title of type1 and type2, type3, amount of money under the title of cash based on type1, type2, type 3 and adding the total credits and cash
and null I show you separate.
TYPE_1_CR TYPE_1_CA TYPE_2_CR TYPE_2_CA TYPE_3_CR TYPE_3_CA TOTAL CASH Null type CASH
Sum (Credit) sum (cash) sum (credit) sum (cash) sum (credit) sum (cash) sum of all type (CR) sum of money (credit) sum, sum (cash)
Kindly give me a suggestion to solve this query
concerning
RDK
Hello
Looks like you want to use the SUM aggregate function, using CASE expressions when you want to include only certain types:
SELECT SUM (CASE WHEN inv_type = 'type1' CAN in the end credit) AS type_1_cr
, SUM (CASE WHEN inv_type = 'type1' CAN collect END) AS type_1_ca
, SUM (CASE WHEN inv_type = 'type2' CAN in the end credit) AS type_2_cr
, SUM (CASE WHEN inv_type = 'type2' CAN collect END) AS type_2_ca
, SUM (CASE WHEN inv_type = 'type3' CAN in the end credit) AS type_3_cr
, SUM (CASE WHEN inv_type = 'type3' CAN collect END) AS type_3_ca
SUM (cash) AS total_ca
The amount (credit) AS total_cr
, SUM (CASE WHEN inv_type IS NULL THEN credit END) AS null_cr
SUM (CASE WHEN inv_type IS NULL THEN silver END) AS null_ca
OF stv_dtls
;
It will work in Oracle 8.1 and higher, but as of version 11.1, you would like to use SELECT... PIVOT.
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
See the FAQ forum: https://forums.oracle.com/message/9362002#9362002
-
Hello
I created a block with 15 records of brands for example for 15 subjects. now, I want to sum up this column, but when I take the text of the Ant or view the item with the sum of the setting of this column in the property happened 15 times. but I need that a registration.
If I'm moving that to other block throwing error. FRM-30377: Preview to the point must reside in the block of single record or within the same block that point summarized.
Please, help me to sum up this column.
Thank youIf I'm moving that to other block throwing error
Place the summary total item in a control block. On the property of this block range, under the box of records, set the property of single record Yes.
-
Hello
My question is - I would like to make the sum of the column "volume".
Current Output ENVIRONMENT Volume Production 79 QA 66 Development 30 Desired Output ENVIRONMENT Volume Production 79 QA 66 Development 30 *Total 175* select * from ( select ci.environment, count(1) "Volume" from tsgdw_task@awhsncp1 t, tsgdw_operational_process@awhsncp1 op, tsgdw_support_group@awhsncp1 sg, tsgdw_person@awhsncp1 p, tsgdw_configuration_item@awhsncp1 ci where sg.SUPPORT_GROUP_SEQ_ID in (SELECT sg2.SUPPORT_GROUP_SEQ_ID FROM tsgdw_support_group@awhsncp1 sg2 start with sg2.SEARCH_CODE = 'DBNONEC' --p_target_name connect by prior sg2.SUPPORT_GROUP_SEQ_ID=sg2. PARENT_SUPPORT_GROUP_SEQ_ID) and t.task_seq_id = op.task_seq_id and sg.support_group_seq_id = op.support_group_seq_id and op.assigned_person_seq_id = p.person_seq_id and op.open_CONFIG_ITEM_SEQ_ID = ci.CONFIGURATION_ITEM_SEQ_ID and t.task_type = 'Change Task' and t.state = 'Closed' --and sg.search_code = p_target_name and ci.environment in ('Production','Development','Staging','QA') and OP.EST_ACTUAL_END_DATETIME between to_date('01-Apr-2012,00:00:00','DD-Mon-YYYY,HH24:MI:SS') and to_date('08-Apr-2012,23:59:59','DD-Mon-YYYY,HH24:MI:SS') --and t.LAST_UPDATE_DATE between ??EMIP_BIND_START_DATE?? and ??EMIP_BIND_END_DATE?? group by ci.environment order by 2 desc) where rownum < 6;
Use the rollup group by
-
I created a form with 12 columns and 23 fixed lines. In line 1 of table is a value, the 22 remaining lines allow the user to enter a number, what I would like task is in the footer line power add up the figures in 22 columns and then multiple that by rank value for a total 1.
Any help would be appreciated.
Hi Steve,.
for now, I'll send your pdf with the calculation script.
You must use the following script in each column in the total field
-Sterling is the objectname in the user input in column 1 in each row field
-Various is the objectname in the user input in column 1 in each row field
- ...
Column $ = Sum(Row1[*].Sterling)* Row1.TTValue Columns $ = Sum(Row1[*].Other)* Row1.OtherValue Column $ = Sum(Row1[*].Banking)* Row1.BankingValue
You understand that?
You must use the [*] the repeated thing, in your, this is the Row1. You can see on the Row1 [0]... Row1 [1). And your amount, for example 4 oder 7.50 needs a static cross reference by column.
I hope I could help?
Mandy
-
Symbol of the missing sum in column a of the measures
Hi, I need Sum (∑) by one of the measures, and this column is missing the ∑ symbol. Why would it be? All other columns have ∑.
Thank you.It won't be shown on measure,
Still one thing that discovers you are using? do you have a screenshot of it?
-
Hello
-How can I add serial number of column in the table of the ADF.
-What is the way to calculate the sum of a column at the end of the table. (Table of the ADF). That is to say.
10
20
15
______
45
Niaz MHello
Here you have some links to blog posts how do the sum:
http://apps.branislavnemec.com/blogs/faces/bjanko/blogs.jsp?blog=bjanko20070725180020
http://Kuba.zilp.pl/?id=781Kind regards
Branislav
Published by: Branislav Nemec June 6, 2011 11:23
-
Help! Calculate a percentage between two fields that the sum of columns
Members of the forum good day!
I'm hoping to get help with and model RTF I use to sum up the output of a query in PeopleSoft.
I have a line with two fields of the query and a third field calculates a percentage using the query fields:
Row1, Field1: EXPR14_14
Row1, Field2: EXPR1_1
Row1, Field3: <? xdofx: If EXPR1_1 <>0 and EXPR14_14 0 then (EXPR1_1 DIV EXPR14_14) <>* 100 or 0 end if? >
I have a second row who has these fields:
Row2, Field1: <? sum (EXPR14_14)? >
Row2, Field2: <? sum (EXPR1_1)? >
Row3, Field3: I need the third field to calculate the percentage of sum of two fields.
I tried different ways to insert this calculation with no luck. It's my first time to create a rtf report and any help would be gratly appreciated.
In advanced thank you for your help.
Kind regards
RaquelFor the calculation of percentage you can use something similar to this (adjust the formula you need)
(sum(current-group() xpr1_1))="" div="" (sum(current-group()/expr14_14)="" )*="" 100?=""?>
For Row1, Field3:(EXPR1_1 div="" expr14_14)*100?=""?>
Hope that helps. If you need more help, send me the xml file and the [email protected] model
Thank you
Bipuser -
sum of a column of the dimension
Hello
If my requirement of report said we get SUM (Treasury of column) of the dimension table then can we do it? I have undersatnd that function must be used for measures in fact table. What are we doing to reach the sum of the columns in the dimension table? The report tries to compare the sum (column done) sum (dimension columns). Earlier when I used the sum on the column dimension function he gave no precise results. Please advice.Unfortunately, I could not explain this matter in a simple unique way, without seeing exactly the report and generated queries
In the simple table, OBIEE is supposed to do something like this (I assume you put the attribute of the year, money and a measure of 'real')
"+ select +".
+ Year +.
+ Sum (cash) +.
+ Sum (fact measure) +.+ Of +.
+ time_dim_table, +.
+ cash_dim_table, +.
+ fact_table +.+ where (joins).
+ Group by year +.
"You can check if the physical demand looks like this, in order to understand the results.
In the PivotTable, it's totally different.
Your physical demand will be no aggregation: so what will:"+ select +".
+ Year +.
+ Cash +.
+ Sum (fact measure) +.+ Of +.
+ time_dim_table, +.
+ cash_dim_table, +.
+ fact_table +.+ where (joins).
+ Group by year, money +.
"But, OBIEE then apply logic calculatiosn to display goods results in the PivotTable.
Who can explain the different results.But don't forget that told you right: avoid the aggregation on the dimension attributes. You can sometimes has good results (ex: using the pivot, or other), but it's not really the best way to make your reports. If you often need a "sum (cash"), create a new table of logic made with the 'picture of cash' (even if it is also a dimension table).
Maybe you are looking for
-
My 5s iPhone is disabled and its 'home' button is also broken. I can't connect to iTunes, and I can put it in recovery mode. I don't know what to do.
-
Safari is the gel on iOS 9.3 on my iPhone 6 s HELP ME
Hello, after the software upgrade on my 6 s with version 9.3 Safari has simply stopped working. I can't check my e-mail or open all alone and page Help, please
-
Pavilion g6: disabled Code Bios
My BIOS is locked by default and I do not know the password, I have disabled BIOS code 53185940
-
Salvation of the France. I tried to access BIOS on HP Envy Code: 867669664 Can I get the reset code? Thank you very much!
-
ATTR_TASKBAR_BUTTON_TEXT
Hello function SetSystemAttribute (ATTR_TASKBAR_BUTTON_TEXT) call, works very well when the program is run under Windows XP. Running the same software on Windows 7, however, only the application icon appears in the bar tasks, but no text. I tend to b