Question about how to calculate an additional column in the query result.
Hello PL/SQL gurus and experts.I use Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64-bit Production version
Currently, I have the data in the following manner-
drop table T2;
create table T2(Year, MastTot, BechTot, Tot) as select
'2008', '20000', '450000', '470000' from dual union all select
'2008', '50000', '324000', '374000' from DUAL union all select
'2009', '25000', '450000', '475000' from dual union all select
'2009', '250000', '324000', '574000' from DUAL union all select
'2010', '120000', '450000', '570000' from dual union all select
'2010', '52000', '324000', '376000' from DUAL union all select
'2011', '220000', '450000', '670000' from dual union all select
'2011', '52000', '324000', '376000' from DUAL ;
I want that data to present the following year (production).Year MastTot %Change BechTot %Change Tot %Change %Total
2009 275000 292.86 774000 0 1049000 24.29 27
2010 172000 -37.45 774000 0 946000 -9.82 24.35
2011 272000 58.14 774000 0 1046000 10.57 26.92
Total 789000 313.54 3096000 0 3885000 25.04 78.28
I use the following sql query-select decode(grouping(Year), 0, Year, 'Total') Year,
To_Char(sum(MastTot), '999,999,999,999,999,999,999.99') "MastTot",
To_Char(sum(BechTot), '999,999,999,999,999,999,999.99') "BechTot",
To_Char(sum(Tot), '999,999,999,999,999,999,999.99') "Tot",
round((sum(Tot)/nullif(max(total_amount),0)) * 100, 2) "%Total"
From
(
select Year,
sum(MastTot) MastTot,
sum(BechTot) BechTot,
sum(Tot) Tot,
SUM(Tot) over() total_amount
From t2
group by Year,Tot
)
where Year>'2008'
group by grouping sets((Year),())
order by Year
But I am not able to read the % change column. Kindly help me with this.All the efforts and assistance in this regard is very appericated and I will be thankful to you...
user555994 wrote:
Thanks for the reply JAC,you are making reference to the line in the code
round((sum(Tot)/nullif(max(total_amount),0)) * 100, 2) "%Total"
Here, I'm looking for the Total % against the maximum value of the tot...
SQL> with t
2 as (
3 select year,masttot,lag(masttot) over(order by year) prevm,
4 BechTot,lag(BechTot) over(order by year) prevb,
5 tot,lag(Tot) over(order by year) prevt,
6 sum(tot) over(order by null) sm_t
7 from(
8 select Year,
9 sum(MastTot) MastTot,
10 sum(BechTot) BechTot,
11 sum(Tot) Tot
12 From t2
13 group by Year
14 ))
15 select year,sum(masttot) masttot,
16 sum(((masttot-prevm)/prevm)*100) Perc_m,
17 sum(BechTot) bechtot,
18 sum(((BechTot-prevb)/prevb)*100) Perc_b,
19 sum(tot) tot,sum(((tot-prevt)/prevt)*100) Perc_t,
20 sum((tot/sm_t)*100) perc_total
21 from t
22 where year > 2008
23 group by rollup(year);
YEAR MASTTOT PERC_M BECHTOT PERC_B TOT PERC_T PERC_TOTAL
---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
2009 275000 292.857143 774000 0 1049000 24.2890995 27.001287
2010 172000 -37.454545 774000 0 946000 -9.8188751 24.3500644
2011 272000 58.1395349 774000 0 1046000 10.5708245 26.9240669
719000 313.542132 2322000 0 3041000 25.0410489 78.2754183
Tags: Database
Similar Questions
-
How to create an additional column for the description of the virtual computer object?
Hi all
I would like to know if it is possible to add a column more in the description of VMware vsphere, for the moment we have column / field called 'Notes' in which we can add our comments on a particular virtual machine / items.
I wanted to add a column called the backup status, is it possible to add it to the database of the VM? which can be edited client VSphere.
Any ideas would be greatly appreciated.
Thank you
AWT
You can add fields for virtual machines.
Click on a virtual machine.
Then, go to the menu Manager
Choose custom attributes.
André
-
Windows Live ID problem
Hello world.
I have a small problem regarding the Windows Live account. My account is: * e-mail address is removed from the privacy *, I forgot my password.I need to answer the questions about my "ID". I don't know the answers that I've tried over and over again and I even tried to make security issues and I could not answer.What can I do?Hello RobertKristof,
The best place to ask your question of Windows Live is inside Windows Live help forums. Experts specialize in all things, Windows Live, and would be delighted to help you with your questions. Please choose a product below to be redirected to the appropriate community:
Looking for a different product to Windows Live? Visit the home page Windows Live Help for the complete list of Windows Live forums to www.windowslivehelp.com.
-
new to 4.02, no grid or column names in the query results
It is a bit strange, I have SQL Developer 4.02 just installed, and I don't see grid or column names in the query results. Don't see anything useful in tools > Preferences, what don't get me?
The worksheet gives you a couple of different ways to run a query...
1. instruction execute sheet icon toolbar (large green arrow, or Ctrl + Enter).
This produces a results tab of the query with the data displayed in a grid.
2. worksheet icon toolbar Execute the Script (the small tip of the green arrow on lined paper, or F5).
This produces a tab out of the Script with the data displayed on the printer.
If execution of the statement to Execute the Script, using some SQL * most orders will remove the column headers:
1. set the position
2. set the pagesize 0 (or 1 or 2).
Pagesize and linesize default is - 1. By default, the spreadsheet is free for formatting output script as he wishes. If you have not changed these settings in the spreadsheet, then see if you point to a startup script in Tools > Preferences > Database > name of the connection startup script file
Kind regards
Gary
SQL DeveloperTeam
-
Oracle BPM 12.2.1 workspace how to add additional columns to the DB table tasklist
Hi all
I need to add some required columns to the table from the list of tasks (for example, activity and status of the activity referred to in the task line), I decompiled adflibTaskListTaskflow.jar and found a class named TaskModel.class in this package: oracle.bpel.worklistapp.tasklist.beans.model, if decompile you this class, you can see that at the table from the list of tasks, data are expressed here by using ITaskQueryService now how more columns may add other tables or is there another easier solution?
Hi Hadi,
You can add columns to your table of task list in the workspace by changing the current view, or even create a new (more and icons in pencil). The situation of activity is available in the list of columns.
You can also add columns to the list view based on flexfields tasks that you create.
If you manually change the adflibTaskListTaskflow.jar you can have problems in the future given that libraries can change between versions and of course are not recommended to do.
I have add columns to the list of tasks, and at that time here, we have created a list of custom task based on BPM Middleware. If you follow this method, you will have complete freedom to show what you want.
-
A question about how to make something similar to a Navigation bar?
Hi guys, I'm sorry if this has been asked before, I just completely sure what I was looking for!
Well, I think my first official for the company website that I work. I was curious about how to make a navigation enough image size, with a little information and a link visitors could click to learn more. I don't know what this method is called or where to start to create a!
I was certainly not specific, but I don't speak of something similar to www.nationalgeographic.com.
At the top of their page, they have a daily news thing, when you click the numbers, it takes you to a picture and a sentence of information and a link at the bottom left for "More".
That's what I was looking for!
I hope you guys can help me, thanks in advance!
Adobe Exchange has several cool widgets that you can use.
http://ALT-Web.com/demos/Spry-test.html
You will need to install Adobe area to use the browser Widget ~ installed from the link below:
http://labs.Adobe.com/technologies/widgetbrowser/
Log-in to Adobe Exchange to enter & configuration desired widgets.
Nancy O.
ALT-Web Design & Publishing
Web | Graphics | Print | Media specialists
-
just need to know how to calculate the percentages as above
Hi ReginaOsterhoudt,
You can see the following link to see if it helps.
How does the calculator percent key work?
In your example, 912,5 * 225/100 = 2053.125
In addition, you can use Microsoft Excel to do the same.
-
Additional columns in the target
Hi all
I am new to ODI and slowly learning how everything goes in ODI. I came across a problem in either the IE interface is I have a source table in the source of the interface with 10 columns box and in the target box, I have a table with 15 columns. I loaded 10 columns in source with 10 columns in the target, and my question is how the rest of the columns must be loaded with "NA" If no column related to them does not appear in the source table? Please help me solve this.
Thank you.In the hardcode the mapping section that you want to enter for example "NA" and in the properties panel that execute on the target (in red color).
Thank you
A -
How to add the label (dRevLabel) as a column in the search results Page
Hello
I need to customize the search results page to display the text in the search result. At present, the review is not available to be included in the columns to display in the search results when you create a custom search template.
Please suggest how to proceed.
Thank you
MalicetI think you want to substitute the dynamichtml include create_core_fields_result_set.
Once you add in your column/one additional field, you should then be able to configure a custom search template (and add your field) and it must be able to handle the rest.
Jonathan
http://jonathanhult.com -
R12 payment process Request Status Report add additional columns to the XML data.
In 11i, we had modified the preliminary report of payment to include additional columns (distributions of invoice). R12, this report is obsolete and Oracle introduced a new report 'Payment process Request Status Report'. This query uses BI Publisher to generate the release of the final report. I can't edit the template for the output XML to the report has not
contains data for distribution invoice account. We need to know how we can modify the XML data to include additional columns.
For the disbursement of funds (payment instructions file) process, Oracle provides extensibility IBY_FD_EXTRACT_EXT_PUB package to build the custom XML element structure that can be added to the extracted XML payment generated by the Oracle payments. Do we have something similar to this report? Are there other options available?
Thank youHello
The same "IBY_FD_EXTRACT_EXT_PUB" package also works for the payment request process status report. Please add the logic to get the distribution data in this package, and you'll see the new XML tags in this report also.
I hope this helps.
Serge -
How to convert a single column in the primary key column
Hi all
I have a column that's unique cnstraint, this column contains the value as digital and also null.
So how do you convert to primary key column
Concerning
PrashantPrashant wrote:
Hi allI have a column that's unique cnstraint, this column contains the value as digital and also null.
So how do you convert to primary key column
Concerning
PrashantPrashant,
You must assign new values to null values. You can use a sequence to produce the figures in this column.
Select max (your_unique_column) from your_table; -find the maximum value of this column, so you can start the sequence of this number.
create sequence seq_for_your_table with XXXX - value max + 1 you have found
Update your_table set your_unique_column = seq_for_your_table.nextval () where your_unique_column is null
You can create a primary key on this column.
Best regards
Grosbois
-------------------------------------------------------
If you answer this question, please mark appropriate as correct/useful messages and the thread as closed. Thank you -
I have a column with two values, separated by a space, in each line. How do I create 2 new columns with the first value in one column and the second value in another column?
Add two new columns after than the original with space separated values column.
Select cell B1 and type (or copy and paste it here) the formula:
= IF (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
shortcut for this is:
B1 = if (Len (a1) > 0, LEFT (A1, FIND ("", A1) −1), ' ')
C1 = if (Len (a1) > 0, Member SUBSTITUTE (A1, B1 & "", ""), "")
or
the formula of the C1 could also be:
= IF (Len (a1) > 0, RIGHT (A1, LEN (A1) −FIND ("", A1)), "")
Select cells B1 and C1, copy
Select cells B1 at the end of the C column, paste
-
Under Options in Firefox, I clicked on save the files under downloads, but the file name twice and an additional file with the same name is created in the folder, i.e.:
G:\Akbar's Songs\HAMARA DOWNLOADS\HAMARA FORUMS DOWNLOADS FORUMS
As you can see the file repeats, how can I fix it?
Also the music files, I download from a site of downloads as a WinRar file and I need to open it. Y at - it an option where the file opens automatically in the folder I chose?
Thanks a lot for your help.
Hi Akush, when you install 7 - zip, make itself the default application to open .zip and .rar files. So if you double click on the .rar file, it should open in 7 - zip. If you prefer to decompress immediately, right click the file and look for new 7 - zip items in the menu. I can't think of a way to do this automatically, however.
-
I have about seven questions about Firefox OS. I'm potentially interested in opting for a tablet that works instead of Android or iOS. I couldn't find a place to ask questions like that. Thank you!
https://support.Mozilla.org/en-us/forums/Firefox-OS-English-Forum
There is another option.
-
How to create a status column in the table
Hello everyone
I am trying to create a column of the table status in frontview Panel. I enclose a picture with her to say clearly what I say.plz tell me how to create the active status column in the table.
I want to show green for safety stock and red for safety stock below.
Maybe you are looking for
-
As soon as Firefox when through it's automatic 'upgrade' the scrolling action became very slow and lazy. I tried all this suggested (disable plug-ins, re-installing Firefox, restart the computer, etc.), but I still can't get back to the way it was. I
-
Can what type of 3D glases I use with my Toshiba 58L7363D?
Hi @ all. IAM new here. IAM 33y old, married and has two children. I bought a Toshiba 58L7363D (no DG) last year. Now my kids want to start with BlueRay´s 3d. I have a 3D BlueRay Player. Now my question... What type of 3d Glases should?Shutter? Or ju
-
Send option is not available when I use msg.reply (true, true) for email
Hello I don't have a send option when you reply to an email below is the code for this: NewMessage message = msg.reply(true,true); Invoke.invokeApplication (Invoke.APP_TYPE_MESSAGES, new MessageArguments (newMessage)); But if I do NewMessage message
-
When you listen to the music, they sound like Chipmunks singing! This can be corrected?
-
BlackBerry Smartphones "BOLD" says that to validate the email out of blue – then reject
Hello- Mail came in fine throughout the day, but this afternoon, I got a message from BB on 9000 "BOLD", saying that I wasn't getting my yahoo mail and needed to validate it. Went into the phone settings to validate, Email validation required red an