Get the sum of all Member of a hierarchy.
HelloI want to get the sum of each Member in a hierarchy.
The hierarchy is defined in the strdet table:
create table strdetThe values for each object/material by costcenter (child) is defined in the details_det table:
(costcenterms varchar2(20), // parent
costcenterdet varchar2(20), // child
lev varchar2(1))
create table details_detSome examples of data:
(costcenterms varchar2(20),
eppid varchar2(30) ,
purchcontyear0 number(4,1) )
insert into strdet values ('1' , '1.1','2')
/
insert into strdet values ('1' , '1.2','2')
/
insert into strdet values ('1.1' , '1.1.1','3')
/
insert into strdet values ('1.1' , '1.1.2','3')
/
insert into strdet values ('1.2' , '1.2.1','3')
/
insert into strdet values ('1.2' , '1.2.2','3')
/
insert into strdet values ('1.2' , '1.2.3','3')
/
insert into strdet values ('1.1.1' , '1.1.1.1','4')
/
insert into strdet values ('1.1.1' , '1.1.1.2','4')
/
insert into strdet values ('1.1.2' , '1.1.2.1','4')
/
insert into strdet values ('1.2.1' , '1.2.1.1','4')
/
insert into strdet values ('1.2.1' , '1.2.1.2','4')
/
COMMIT;
insert into details_det values('1.1.1.1','epp1',10);The desired sql stmt output should be like this:
insert into details_det values('1.1.1.1','epp2',20);
insert into details_det values('1.1.1.1','epp3',0);
insert into details_det values('1.1.1.2','epp1',0);
insert into details_det values('1.1.2.1','epp2',5);
insert into details_det values('1.1.2.1','epp4',15);
insert into details_det values('1.2.1.1','epp1',65);
insert into details_det values('1.2.1.1','epp2',95);
insert into details_det values('1.2.1.2','epp1',5);
commit;
costcenter valI wrote the following, so far...
-------------- ------
1 220
1.1 55
1.2 165
1.1.1 30
1.1.2 20
1.2.1 165
SQL> select distinct s.costcenterms , sum(purchcontyear0) over(partition by s.costcenterms order by s.costcenterms)How should I modify the above sql stmt to get the result you want...?
2 from details_det d , strdet s
3 where s.costcenterdet=d.costcenterms(+)
4 start with s.costcenterms='1'
5 connect by s.costcenterms = prior s.costcenterdet
6 order by s.costcenterms
7 /
COSTCENTERMS SUM(PURCHCONTYEAR0)OVER(PARTIT
------------------------------------------------------------ ------------------------------
1.2
1.2.1 165
1.1.1 30
1.1.2 20
1
1.1
6 rows selected
Note: I use OracleDB 10 g. v.2
Thank you very much
SIM
sgalaxy wrote:
Anyway, since I want to use the sql stmt to define a materialized view, all versions of data of hierarchical queries are not allowed... (oracle ora-30361 error...).
No error on my:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
SQL> create materialized view x_mv
2 as
3 select grp,
4 sum(purchcontyear0)
5 from (
6 select connect_by_root s.costcenterms grp,
7 d.purchcontyear0
8 from strdet s,
9 details_det d
10 where s.costcenterdet=d.costcenterms(+)
11 connect by s.costcenterms = prior s.costcenterdet
12 )
13 group by grp
14 /
Materialized view created.
SQL> select *
2 from x_mv
3 order by grp
4 /
GRP SUM(PURCHCONTYEAR0)
-------------------- -------------------
1 215
1.1 50
1.1.1 30
1.1.2 20
1.2 165
1.2.1 165
6 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
try to get the SUM of all of the charges with the having clause
Hi Oracle users.
I'm trying to accomplish to get a sum of a series of charges and it should be easy, but I can't get it.
For example, I have the following.
Select ACCTLOC, count(ACCTLOC) AS TOTALP FROM BOX_ACCTS_TBL WHERE TIME_REQ > SYSDATE-120 Group By ACCTLOC having (count(ACCTLOC) > 1) the results are ACCTLOC TOTALP Philly 15970 NY 8623 Tacoma 3 SanFran 195 Hartford 5 Miami 4374
How can I get the SUM of this group? Do I put this in PL SQL and do a procedure to carry out the selection? Is this the way to go on this?
I appreciate all the comments you can give.Thank you!
with
query_result as
(select 'Philly' acctloc, 15970 totalp Union double all the)
Select "NY", 8623 Union double all the
Select "Tacoma", 3 double Union all
Select "SanFran", 195 double Union all
Select "Hartford", 5 Union double all the
Select 'Miami', double 4374
)
Select acctloc, totalp, sum (totalp) on the_sum, avg (totalp) (on the_avg), ratio_to_report (totalp) (percentages))
of query_result
ACCTLOC TOTALP THE_SUM THE_AVG PERCENTAGES Philly 15970 29170 4861.66666666666666666666666666666666667 .547480287967089475488515598217346588961 NY 8623 29170 4861.66666666666666666666666666666666667 .295611930065135413095646211861501542681 Tacoma 3 29170 4861.66666666666666666666666666666666667 .000102845389098388755570791909496057593 SanFran 195 29170 4861.66666666666666666666666666666666667 .006684950291395269112101474117243743572 Hartford 5 29170 4861.66666666666666666666666666666666667 .000171408981830647925951319849160095989 Miami 4374 29170 4861.66666666666666666666666666666666667 .149948577305450805622214604045251971203 Concerning
Etbin
-
How to get the last row and the sum of all columns in a query
Hello
is there a way to get the last record for a column and the sum of all the Archives to another column in the same query.
Best regards
You must set your needs correctly volunteers to help here...
Your data are not good enough to bring you a precise solution. Purpose, you do not have a column, which draws a distinction between the first and the last entry.
The solution becomes easy based on your design.
I introduced a grouping called 'id' column and a time column called 'time_of_insert' (only this way you can say with confidence that you can differentiate between the first and last (also a foolproof solution) - you can possibly use sequence (instead of date but if you say that you can insert two lines at the same time) ((and then likely sequence would be a better choice to differentiate instead of a timestamp field) etc...)
With your sample data, something like this can be done to get the desired results.
-----------------------------------------------------------------------------------------------------------------------
WITH dataset AS
(SELECT 1 id, 10 used, 8 remain, systimestamp + 1/24 time_of_insert FROM DUAL
UNION ALL
SELECT the 1 id, 1, 7, systimestamp + 2/24 FROM DUAL
UNION ALL
SELECT the id 1, 2, 5, systimestamp + 3/24 FROM DUAL
UNION ALL
SELECT 1 id, 1, 0, systimestamp + 4/24 FROM DUAL
UNION ALL
SELECT 1 id, 0, 0, systimestamp + 5/24 FROM DUAL
UNION ALL
SELECT the 1 id, 1, 4, systimestamp + 6/24 FROM DUAL)
SELECT *.
(SELECT SUM (used) ON sum_all)
FIRST_VALUE (stay)
COURSES (PARTITION BY id ORDER BY time_of_insert DESC)
last_row
Of THE dataset)
WHERE ROWNUM = 1;
Output:
------------------------
SUM_ALL LAST_ROW
------------------------------
15 4
See you soon,.
Manik.
-
to get the sum of the balance_due
Hi all
I have this request with meSELECT rac.customer_number, rac.customer_name, su.LOCATION contract, SUBSTR (sa.NAME, 1, 2) bu, ra.purchase_order_date sub_date, ra.invoice_currency_code ccy,RA.PURCHASE_ORDER,ra.trx_number, TRUNC (rad.gl_date) gl_date, SUM (npar_get_invoice_balance (ra.customer_trx_id, '08-Sep-2011' ) ) balance_due FROM ra_customer_trx_all ra, ra_site_uses_all su, ra_cust_trx_line_gl_dist_all rad, ra_customers rac, ra_cust_trx_types_all ty, ra_salesreps_all sa WHERE TRUNC (rad.gl_date) <= '08-Sep-2011' AND ra.bill_to_customer_id = rac.customer_id AND su.site_use_code = 'BILL_TO' AND su.site_use_id = ra.bill_to_site_use_id AND ty.cust_trx_type_id = ra.cust_trx_type_id AND ty.TYPE = 'INV' AND ty.org_id <> -3113 AND rad.customer_trx_id = ra.customer_trx_id AND rad.account_class = 'REC' AND rad.latest_rec_flag = 'Y' AND npar_get_invoice_balance (ra.customer_trx_id, '08-Sep-2011') <> 0 AND sa.salesrep_id(+) = ra.primary_salesrep_id AND sa.org_id(+) <> -3113 and ra.purchase_order='2011-0526' GROUP BY rac.customer_number, rac.customer_name, su.LOCATION, ra.invoice_currency_code , ra.trx_number, RA.PURCHASE_ORDER, rad.gl_date, ra.purchase_order_date, ra.invoice_currency_code, SUBSTR (sa.NAME, 1, 2) with the following output CUSTOMER_NUMBER CUSTOMER_NAME CONTRACT BU SUB_DATE CCY PURCHASE_ORDER TRX_NUMBER GL_DATE BALANCE_DUE 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-M 05/23/2011 4,773.60 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-S 05/23/2011 3,559.78
Inorder to get this output I have to avoid the group clause trx number and then only to get the sum of the 8333.38, but I need trx number too in my query.i require the following output CUSTOMER_NUMBER CUSTOMER_NAME CONTRACT BU SUB_DATE CCY PURCHASE_ORDER TRX_NUMBER GL_DATE BALANCE_DUE 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-M 05/23/2011 8333.38 1002 Joint Operations (KGOC / SAC) JO/SA88/WO06 12 05/29/2011 KWD 2011-0526 2011-0526-S 05/23/2011 8333.38 ie balance due is sum of the balances of trx numbers 2011-0526-M and 2011-0526-S(4733.60+ 3559.78)
Can this be achieved
kindly help
thanking in advanceSomething like:
SELECT rac.customer_number, rac.customer_name, su.LOCATION contract, SUBSTR (sa.NAME, 1, 2) bu, ra.purchase_order_date sub_date, ra.invoice_currency_code ccy,RA.PURCHASE_ORDER,ra.trx_number, TRUNC (rad.gl_date) gl_date, SUM( SUM(npar_get_invoice_balance( ra.customer_trx_id, '08-Sep-2011' ) ) OVER( PARTITION BY rac.customer_number, rac.customer_name, su.LOCATION, ra.invoice_currency_code , RA.PURCHASE_ORDER, TRUNC (rad.gl_date), ra.purchase_order_date, ra.invoice_currency_code, SUBSTR (sa.NAME, 1, 2) ) ) balance_due FROM ra_customer_trx_all ra, ra_site_uses_all su, ra_cust_trx_line_gl_dist_all rad, ra_customers rac, ra_cust_trx_types_all ty, ra_salesreps_all sa WHERE TRUNC (rad.gl_date) <= '08-Sep-2011' AND ra.bill_to_customer_id = rac.customer_id AND su.site_use_code = 'BILL_TO' AND su.site_use_id = ra.bill_to_site_use_id AND ty.cust_trx_type_id = ra.cust_trx_type_id AND ty.TYPE = 'INV' AND ty.org_id <> -3113 AND rad.customer_trx_id = ra.customer_trx_id AND rad.account_class = 'REC' AND rad.latest_rec_flag = 'Y' AND npar_get_invoice_balance (ra.customer_trx_id, '08-Sep-2011') 0 AND sa.salesrep_id(+) = ra.primary_salesrep_id AND sa.org_id(+) -3113 and ra.purchase_order='2011-0526' GROUP BY rac.customer_number, rac.customer_name, su.LOCATION, ra.invoice_currency_code , ra.trx_number, RA.PURCHASE_ORDER, rad.gl_date, ra.purchase_order_date, ra.invoice_currency_code, SUBSTR (sa.NAME, 1, 2) /
SY.
-
How to get the sum of the first row in the previous row?
Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line. Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?Hello
kamranpathan wrote:
Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line.If you do not explicitly give a windowing clause, then you get the default windowing clause you indicated.
If you want another clause of windowing, ionclude in the analytic function call.Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?
Yes. The correct syntax for "Previous rank" is «PREVIOUS 1»
... ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING
For more information, search for "Analytic Functions" in the manual of the SQL language:
http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions004.htm#sthref917I hope that answers your question.
If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using.
You will find the answers better faster if you always provide this information whenever you post a question.Published by: Frank Kulash, Sep 17, 2011 17:04
I just saw Etbin responses.
As usual, Etbin has a good point. If the column that you are basically cannot be NULL, then it is probably easier to subtract the total current line and use the default windowing clause.
Even if it can be null, you find may be easier to use this approach. -
20 GB difference between space and the sum of all files
my c: drive displays of 42.5 GB used space. the sum of all folders on the c: is 22 GB. make all the folders and files not hidden. I just deleted a user account. the files could still be in the cache somewhere? recovery partition is less than 1 GB. Thank you!!
To study disk space, use download and install Treesize (freeware).
http://www.Jam-software.com/treesize_free/Information about Treesize
http://www.Jam-software.com/treesize_free/When you open Treesize scan select in the Menu and you will see a list of drives. Click on C and it will generate a list of files.
Display names and 6 larger files sizes and the total at the top of the list.
-
Mr President.
I have to take the column values from3, or 4 tables and two of them need to be multiplied, then get the sum of this value multiplied by using Group by and order clause.
as below
cust_id prod name Qty. rate value totalValue 01 one 01 500 500 01 b 02 400 800 1300 How to get there
Select
cstmr.cust_id CustId,
PRDT. Name AutoCAD,
SL.sal_qty SalQty,
SL.unit_sal_price UnitSalPrice,
SL.sal_qty * SL.unit_sal_price as SalVal,
Sum(SL.sal_qty*SL.unit_sal_price) as TotalSalesValue
Of
cstmr customer,
salesLine sl,
prdt product
where
PRDT.prod_id = sl.prod_id
Group
cstmr.cust_id,
PRDT. Name,
SL.sal_qty,
SL.unit_sal_price
order by
cstmr.cust_id
Concerning
Your expected results include values that are not in your input data - there is no M.BOARD product, for example. This is an adaptation of Manik code that will give you the subtotals for each customer:
SELECT client_name c.nom,
product_name p.Name,
SL.sal_qty,
SL.unit_sal_price,
SL.sal_qty * SL.unit_sal_price AS salesvalue,
CASE
WHEN ROW_NUMBER () OVER (partition by order of c.cust_id p.prod_id desc, sl.sal_id desc) = 1 THEN
SUM (sl.sal_qty * sl.unit_sal_price) OVER (PARTITION BY c.cust_id)
END totals
FROM customer c INNER JOIN sales s ON s.cust_id = c.cust_id
INNER JOIN salesline sl ON sl.sal_id = s.sal_id
INNER JOIN product p ON p.prod_id = sl.prod_id
ORDER BY c.cust_id, p.prod_id, sl.sal_id
You could get the grand total of lines by the Union in a second query, or by doing something smart using ROLLUP. But I leave that to you because I think you should at least do some of your own homework.
-
I would like to get the list of all devices on which my creative cloud has been activated for the last six months or a year
I do not think that information... Adobe titles represent the only link I know following your accounts, but not where the programs are installed
https://Accounts.adobe.com/ , then click on Plans & products above to find a list of your programs and your serial numbers
-
Can I get the videos for all of the concepts of photoshop learning?.
I have an account paying adobe... Can I get the videos for all of the concepts of photoshop learning?.
All I see is that links like
CC Photoshop tutorials | Learn how to use Photoshop CC
Above links are available even without an account.
Should I have any extra advantage to access additional videos (as in lynda.com where they have the series of videos that explain how to do something with explanation of the concept)
Originally, there was a selection of 'members only' videos on the Adobe Web site. But this project was abandoned and all content has been made public.
-
Display the sum of all salaries of employees @ footer section
Hi team,
I use Jdev 11.1.2.3.0 version.
I have a requirement where I need to see the sum of all the wages of employees in the employee table footer section in the user interface.
Is there a declarative approach to this question without using any method Java and master-details relationship.
Let me know if you need additional information on my problem.
Thanks in advance,
Check out ADF - Groovy amounting to Total of a column in a Table. Techartifact that should make your use case.
Timo
-
Get the DDL for all tables in a schema;
Hello
I tried to get the DDL for all tables under my own diagram "A". Here are the steps I've tried, but in vain I
1. logged in as a user A 2. And the ran query SELECT DBMS_METADATA.get_ddl ('TABLE', 'XYZ') FROM user_tables o/p (HugecloB) {code} Any idea how i can get the DDL for all the tables under my own schema ? Thank you so much! Edited by: user642297 on Feb 4, 2011 12:05 PM Edited by: user642297 on Feb 4, 2011 12:05 PM Edited by: user642297 on Feb 4, 2011 12:05 PM Edited by: user642297 on Feb 4, 2011 12:07 PM
Your idea is good, you missed only to use the correct table name:
SELECT DBMS_METADATA.get_ddl ('TABLE', table_name) FROM user_tables;
Concerning
-
The sum of all the "ER" element under the service tag
Hi gurus
I'm trying to add up all the values of Er under the tag of benefits. But tag Er resumes on different tags in my document xml, as shown below. can you help me provide how to create the sum for all these Er values under the tag of benefits. I appreciate your help. Here is my xml document.
< benefits >
< insurance >
< REIMBURSED >
< < /ee > ee > 65
< > 1000 < /er > er
< / REIMBURSED >
< dentalinsurance >
< < /ee > ee > 65
< > 1000 < /er > er
< / dentalinsurance >
< / insurance >
< refinementbenefits >
< socialsecurity >
< < /ee > ee > 1000
< > 1000 < /er > er
< / socialsecurity >
< c401K >
< < /ee > ee > 1500
< > < /er > 1500 St
< / c401K >
< / refinementbenefits >
< timeoffbenefits >
< holiday >
< ee > < /ee >
< > < /er > 1500 St
< / holiday >
< sick >
< ee > < /ee >
< > < /er > 2200 St
< / sick >
< holiday >
< ee > < /ee >
< > < /er > 3000 St
< / holiday >
< / timeoffbenefits >
< mandatedbenefits >
< fedunemp >
< ee > < /ee >
< > < /er > 200 er
< / fedunemp >
< stunemp >
< ee > < /ee >
< > 1000 < /er > er
< / stunemp >
< / mandatedbenefits >
< specialbenefits >
< freeparking >
< ee > < /ee >
< > 1000 < /er > er
< / freeparking >
< cell >
< ee > < /ee >
< > 1000 < /er > er
< / mobile phone >
< education >
< ee > < /ee >
< > 1000 < /er > er
< / education >
< / specialbenefits >
< / benefits >Hello
U can try to use
Thank you.
-
How get the sum of differences in time
I have the query to get the taken (duration) of time to perform each activity below
Select (select ep.name PE env_mapping where ep.id = p.bsa_env_id) environment,
(Select trunc ((Max (ps.actual_end) - Min (ps.actual_start)) * 24 * 60) of ps Highlevel_activity where ps.activity_ID = p.id and ps.out_of_window_flag =' no. "") Actual_duration,
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Apps Patching"and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Apps_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, Highlevel_activity ps where de.task_type = ' Patching DB/MT ' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') DB_MT_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Shut Down' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Shut_Down,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Start Up' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Start_Up,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Vérification' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') audit.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching meadow' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Pre_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching Post' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Post_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Others' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') others
activity p where
I get the output as below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33
My requirement is to get the amount for each column which I get on top of the query. How can I change the query above to get as the result below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33
177 74 34 34 15 50 67 33 total
Please help
Thank you
ArchanaHello
Agowda wrote:
I have the query to get the taken (duration) of time to perform each activity belowSelect (select ep.name PE env_mapping where ep.id = p.bsa_env_id) environment,
(Select trunc ((Max (ps.actual_end) - Min (ps.actual_start)) * 24 * 60) of ps Highlevel_activity where ps.activity_ID = p.id and ps.out_of_window_flag =' no. "") Actual_duration,
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Apps Patching"and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Apps_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, Highlevel_activity ps where de.task_type = ' Patching DB/MT ' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') DB_MT_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Shut Down' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Shut_Down,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Start Up' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Start_Up,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Vérification' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') audit.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching meadow' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Pre_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Patching Post' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = ' NO') Post_Patching,.
(select nvl (trunc ((max (de.actual_end) - min (de.actual_start)) * 24 * 60), '0') Detail_activity time_taken, ps Highlevel_activity where de.task_type = 'Others' and ps.activity_id = p.id and.) Highlevel_activity_id = ps.id and ps. OUT_OF_WINDOW_FLAG = 'NO') othersactivity p where
If you make 9 of subqueries to get 9 different columns. It is very inefficient, and it is also difficult to maintain. If you need to change the conditions in subqueries, you will need to do the exact same change at 9 different locations.
It would be much more effective if you just add de.task_type to the GROUP BY clause and then rotates the results. He could not run 9 times faster, but it probably run 5 times faster.
See the FAQ forum {message identifier: = 9360005} to find out how.I get the output as below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33My requirement is to get the amount for each column which I get on top of the query. How can I change the query above to get as the result below
EnV1 27 April 13 167 54 29 29 15 0 0 67 0
EnV2 may 3 13 10 20 05 05 0 0 50 0 33
177 74 34 34 15 50 67 33 totalIt's a GROUPING DEFINED work, no ACCUMULATION.
Since you post CREATE TABLE and INSERT statemennts for your sample data, I will use the hr.departments table to show the difference.
When you GROUP BY N > 1 the expressions, ROLLUP gives you N + 1 levels of totals and subtotals. For example:SELECT department_id , job_id , SUM (salary) AS total_sal FROM hr.employees GROUP BY ROLLUP (department_id, job_id) ORDER BY department_id, job_id ;
The above query GROUPs BY s expressions (department_id job_id) so ROLLUP produces 3 sorts of totals:
(1) total department_id and job_id (e.g. 13000 for department_id = 20 and job_id = "Fatyty" below)
(2) total Department, including all of the work (e.g. 6000 = 19000 13000 + for department_id = 20) and
(3) total general for the entire result (e.g. 691416)DEPARTMENT_ID JOB_ID TOTAL_SAL ------------- ---------- ---------- 10 AD_ASST 4400 10 4400 20 MK_MAN 13000 20 MK_REP 6000 20 19000 30 PU_CLERK 13900 30 PU_MAN 11000 30 24900 40 HR_REP 6500 40 6500 50 SH_CLERK 64300 50 ST_CLERK 55700 50 ST_MAN 36400 50 156400 60 IT_PROG 28800 60 28800 70 PR_REP 10000 70 10000 80 SA_MAN 61000 80 SA_REP 243500 80 304500 90 AD_PRES 24000 90 AD_VP 34000 90 58000 100 FI_ACCOUNT 39600 100 FI_MGR 12008 100 51608 110 AC_ACCOUNT 8300 110 AC_MGR 12008 110 20308 SA_REP 7000 7000 691416
You don't want all that: you just want what corresponds in total for each department_id and job_id and total general, without any level of iintermediate. Here's how you can achieve these results using GROUPING SETS instead of ROLLUP:
SELECT department_id , job_id , SUM (salary) AS total_sal FROM hr.employees GROUP BY GROUPING SETS ( (department_id, job_id) , () ) ORDER BY department_id, job_id ;
DEPARTMENT_ID JOB_ID TOTAL_SAL ------------- ---------- ---------- 10 AD_ASST 4400 20 MK_MAN 13000 20 MK_REP 6000 30 PU_CLERK 13900 30 PU_MAN 11000 40 HR_REP 6500 50 SH_CLERK 64300 50 ST_CLERK 55700 50 ST_MAN 36400 60 IT_PROG 28800 70 PR_REP 10000 80 SA_MAN 61000 80 SA_REP 243500 90 AD_PRES 24000 90 AD_VP 34000 100 FI_ACCOUNT 39600 100 FI_MGR 12008 110 AC_ACCOUNT 8300 110 AC_MGR 12008 SA_REP 7000 691416
I hope that answers your question.
If this isn't the case, post CREATE TABLE and INSERT statements for some examples of data and the results desired from these data.
Simplify the problem. For example, instead of 9 different task_types, post sample data and results for 3 task_types. Simply mention that you actually 9, and we will find a solution that can be easily adapted for 9.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}Published by: Frank Kulash on May 27, 2013 10:47
-
How can I get the homepage where all sites are in boxes on the first screen?
Firefox continued to run slowly and websites was jerky. I tried a bunch of '' correction '' of the others and as a last resort, replace Firefox to its original settings. Now, I lost the start page and can't find how to get it back. I don't want tabs at the top of my browser - just the boxes with all the sites I had before. Where can I find the answer?
Then you which means the page new tab where it shows the 9 most visited sites? You can set your home page in the window of Options of Firefox in about: newtab. Are you meaning?
-
Get the names of all cases by programming in a case structure
Hi all
I have a Subvi, which is a diagram of States (some control test equipment), with many States (i.e. each "State" is a case of a business structure), a text string chooses the case. All cases are appointed.
In this sub - is VI possible for me to get programmatically the name of text for each case of this business structure? I want to be able to recover these channels so that the main VI will be able to call the valid States.
I have the error handling to ensure that if a State not valid is called (using the default case) that an error will be returned to my main vi, but I prefer to be able to retrieve the string to avoid any typo etc.
Don't know if I've explained this well.
Thank you
DS1
ds_1 wrote:
[...] The script I can watch in many it may seem a little complex [...]
It is not too complex, but it won't work in an executable file. This program gets a reference to the structure of the case (by searching for the text of the label) and returns a list of names of frame.
Perhaps my plugin CaseSelect will help you with your Machine States based on a string. You can put any valid States in string constants by double-clicking a list of cases.
Maybe you are looking for
-
Hello I travel a bit and I'm looking for the ideal iPad/AirPrint printer installation. In some places, wifi is unstable or not supplied. Cellular service may be non-existent. I have an iPhone that has no personal hotspot capabilities, but without cel
-
Satellite A200-1BQ - BIOS update failed
Hello everyone I update the BIOS of my laptop and something went wrong: () now my laptop does not turn on the screen. I went to see on the web about Cree Bios recover. I created my floppy drive and I am using a USB drive connected to the USB port on
-
My Qosmio X 870 becomes hot during the WoW game - always shuts down
Hello I have not had this computer for too long, and at first it worked perfectly. I have played World of Warcraft on settings graphic high and so on. But lately, especially when you play raids, it gets REALLY hot and suddenly everything stops. The b
-
Slow down the video with NBPC CQ42-273TU problem
Hello I have NBPC Compaq Presario CQ42-273TU. In my laptop, if I play the video, it becomes very slow. After the video becomes slow, everything else on the laptop becomes slow. recently I gave laptop for the service too, and I also have the problem
-
How to restore deleted Disk Defragmenter icon
I recently had my Disk Defragmenter icon left the tools for the Office System. I accidentally deleted the icon a few days later and I also ran a disk clean up. Now when I try to use Disk Defragmenter, windows says that the shortcut does not exist. Al