Helps with the sum on partition
Hi all
This is my sample data:
create table general( general_id number, general_type nvarchar2(10), start_year number, end_year number, fy number, fy_value number ); insert into general(general_id, general_type, start_year, end_year, fy, fy_value) values (1, 'data 1', 2009, 2013, 2010, 10); insert into general(general_id, general_type, start_year, end_year, fy, fy_value) values (1, 'data 1', 2009, 2013, 2013, 20); insert into general(general_id, general_type, start_year, end_year, fy, fy_value) values (2, 'data 2', 2010, 2014, 2010, 5); insert into general(general_id, general_type, start_year, end_year, fy, fy_value) values (2, 'data 2', 2010, 2014, 2013, 15); SELECT general_id, general_type, fy, sum(fy_value) over (partition by general_id, general_type order by fy) sum_fy_value FROM general
My results:
GENERAL_ID GENERAL_TYPE FY SUM_FY_VALUE 1 data 1 2010 10 1 data 1 2013 30 2 data 2 2010 5 2 data 2 2013 20
How can I complete the sum of the missing years (with leading zeros), from my year start and end?
Example of final results:
GENERAL_ID GENERAL_TYPE FY SUM_FY_VALUE 1 data 1 2009 0 1 data 1 2010 10 1 data 1 2011 10 1 data 1 2012 10 1 data 1 2013 30 2 data 2 2010 5 2 data 2 2011 5 2 data 2 2012 5 2 data 2 2013 20 2 data 2 2014 20
Oracle Database 11g - 11.2.0.4.0
Thanks in advance.
SQL> with t 2 as 3 ( 4 select general_id 5 , general_type 6 , start_year + (level-1) fy 7 from ( 8 select distinct general_id 9 , general_type 10 , start_year 11 , end_year 12 from general 13 ) 14 connect 15 by level <= end_year - start_year + 1 16 and prior general_id = general_id 17 and prior dbms_random.value is not null 18 ) 19 select t.general_id 20 , t.general_type 21 , t.fy 22 , sum(nvl(g.fy_value, 0)) over(partition by t.general_id order by t.fy) sum_fy_value 23 from t 24 left join 25 general g 26 on t.general_id = g.general_id 27 and t.fy = g.fy 28 order 29 by general_id 30 , fy; GENERAL_ID GENERAL_TY FY SUM_FY_VALUE ---------- ---------- ---------- ------------ 1 data 1 2009 0 1 data 1 2010 10 1 data 1 2011 10 1 data 1 2012 10 1 data 1 2013 30 2 data 2 2010 5 2 data 2 2011 5 2 data 2 2012 5 2 data 2 2013 20 2 data 2 2014 20 10 rows selected.
Note: I must say that it is one of these well posed the question, which we do not often here. I appreciate you providing sample data and expected outcomes in a well-formatted way and also provides the oracle version 4-digit.
Tags: Database
Similar Questions
-
Help with the query to select only one record from the result set in double
Hello
Please help with the query. Version of Oracle database we use is 10g R2.
I have a vision that is duplicated IDS, but they are used across the different functions. See below examples of data. Please help me with a query to select only one record (based on ID regardless of the area) from the bottom of the result set of duplicate records. For what is the point of view is there unique records, given the combination of the fields ID, Org, DF, dry, Sub-Sec
ID Org DF Sec Sub-Sec (163) CQ CPDM CPDM HD (163) PC ENG ENG ENG (163) CQ ASIC ASIC IS 8888 TS TAC TAC TAC (163) TS HE HE SW 6789 CQ INFO INFO FOS 6789 PC SECSYS SECSYS INFO1 6789 TS SECSYS SECSYS INFO2 9009 PC BMS BMS BMS1 My result set must eliminate the duplicate identifiers regardless of whoever we choose of the result set. (I mean without distinction Org, DF, s, Sub-s). My expected result set should be.
ID DSB DF SEC Sub-Sec (163) CQ CPDM CPDM HD 8888 TS TAC TAC TAC 6789 CQ INFO INFO FOS 9009 PC BMS BMS BMS1 Thank you
Orton
Hello
This sounds like a job for ROW_NUMBER:
WITH got_r_num AS
(
SELECT id, DSB, df, s, sub_sec org
ROW_NUMBER () OVER (PARTITION BY ID.
ORDER BY org
) AS r_num
OF view_x
)
SELECT id, DSB, df, sub_sec s,
OF got_r_num
WHERE r_num = 1
;
He is a Top - N query example, where you choose the elements of N (N = 1 in this case) from the top of an ordered list.
I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT, only relevant columns instructions) to your sample data and the results desired from these data. (I know that you said that you were a view selection. Just for this thread, pretending it is a picture and post simple CREATE TABLE and INSERT statements to simulate your point of view).
Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places. (I didn't quite understand the explanation above. I don't know why you want toID ORG DF DRY SUB_SEC
-- --- -- --- -------
1234 CQ DPRK DPRK HD
and is not
1234 IS CQ ASIC, ASIC
or
TS 1234 IT IT SW
or
1234 CQ ASIC ASIC HD
)
If you change the query at all, post your modified version.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).See the FAQ forum: https://forums.oracle.com/message/9362002
-
Need help with the data storage store, local array and network connections
Need help with my ESXi 4.1 installation
My hardware:
I built a server with an Asus P6T whitebox, i7 920, 12 Gig RAM, NIC, Intel Pro1000 PT Quad, 3ware 9650SE-12ML with 8 1.5 TB SATA green in a raid 6 array gives me about 8 + TB with a spare drive all housed within a NORCO RPC-4220 4U Rackmount Server chassis. I also have a 500 GB SATA drive which will hold the ESXi and virtual machines.
The network includes a firewall, Netgear Prosafe FVS336G, GS724Tv of Netgear ProSafe 24 port Gigabit Managed Switch on a dhcp cable modem internet service provider.
I also have 2 old NetGear SC101T NAS disks (4to) I want to connect to the system how some - at a later date have... data on them and want to transfer to the new storage array. I always looking into the question of whether they will work with ESXi 4.1, or I might have to only access it through Windows XP.
My Situation:
I have already installed ESXi 4.1 and vsphere client with no problems and it is connected to a dhcp cable internet service. I've set up host via a dynamic DNS service name give me a static hostname on the internet. I installed three machines to virtual OS successfully at the moment and now want to first start by creating a multimedia storage server which will use some of this new 8 TB array, then separate data storage for use with a web server small overhead storage and a backup. It is a domestic installation.
Help with the data store and network:
I was doing some reading, because I'm new to this, and it looks like I'll probably want to set up my table via ESXi as a nfs disk format. Now, the data store is usually in another physical box from what I understand, but I put my readers and ESXi all in the same box. I'm not sure that the best way to put in place with grouped network cards, but I want to make this work.
I understand that in ESXi 4.1 using iSCSi LUN must be less than 2 TB, but nfs - I should be able to add a bigger partition then 2 TB (for my multimedia) in nfs, right? or should I still add it separately as a separate 2 TB drives and then extend them to get the biggest space.
Any suggestions or direct resources showing examples on how to actually add some parts of the table as data warehouses separate nfs. I know that to go to the configuration tab, and then select Add to storage, and then select nfs. I have not my picture, but it's here that I don't know what to do because ESXi 4.1 system already has an address, should I put the same thing to the new data store array also (will it work?), and what should I use for the name of the folder and the store of data... just do something to the top. I thought to later install Openfiler (for a multimedia storage using this table server) as a virtual machine, use the table with esxi so that I can access the same storage space with widows and linux-based systems.
I also know I have to find a way to better use my quad nic card... put in place of virtual switches, grouping, etc HELP?
Any direction, assistance, similar facilities to sample, suggestions or resources that would help would be great. I did a lot of hunting, but still a little confused on how to best to put in place.
You must think of VMDK files of large databases with records of random size guest go read some data (a DLL or an INI file), maybe write some data back, then go read other data. Some files are tiny, but certain DLLs are several megabytes. It's random i/o all and heavy on the search time. IO Opsys is small random operations that are often sequential (go read data, write data, go read other data,...) so that deadlines are critical to the overall performance. That's why people say OPS are / s of reference and forget the MBs flow. The only time where you bulk transfers are when you read media (ISO files).
Well, now forget all this. Actually the disk activity will depend on the specific applications (database? mail server? machines compiler?), but the above is true for boots, and whenever applications are idle. You should see the profile to know.
RAID 10 is faster (and often more reliable) than RAID 5 or RAID-6 except in certain specific cases. In General RAID 10 is ideal for many random writes, since the calculation of parity for RAID-5 and - 6 adds to the overall latency between command and response - latency is cumulative if a little slow here and a little slow it adds up to a lot of overall slow synchronous especially with e/s on a network. OTOH RAID-5 and -6 can produce faster readings due to the number of heads, so you can use it for virtual machines that transfer bulk. Test. You may find that you need several different types subdashboards for best results.
You said 3ware, they have some good grades on their site, but don't believe it. With my 9650 that I found myself with only a couple of their recommendations-, I put the (simple) table for allocation size 256 k, nr_requests at 2 x the queue_depth and use the planner date limit. I had the habit for the Ext4 file system formatted with stride and stripe-width synced to the table and used the options large_files with fewer inodes (do not use the huge_files option unless you plan to have single VMDK files in the terabyte range). Use a cache of great reading in advance.
Virtual machines use VMDK files in all cases except raw iSCSI LUN that they treat native disks. VMDK is easier to manage - you can make a backup by copying the file, you can move it to a PC and load it into another flavour of VMware, etc. There could be some features iSCSI to your San as a transparent migration but nothing for me. NFS has less chatter of Protocol if latency lower times to complete an operation. NFS is good to read and write a block of data, that's all it boils down to.
UPS is good, but it won't help if something inside the machine explodes (UPS does nothing if the PC power supply goes down). If the RAID card has an option for a battery backup module, so it can contain some writings in memory and may end up the disk i/o after replacing the power supply. 3ware also limits the types of caching available if help is not installed, and you get just the right numbers with the module.
-
need help with the query, thx
Hello
I need a little help with the query I have to write;
the table has 4 columns:
what I am asking is the following result: salary according to the latest available yearcol1 col2 col3 col4 emp_name empl_id salary year content of data: col1 col2 col3 col4 smith 12 1200 1999 smith 12 1340 2000 smith 12 1500 2001 jones 13 1550 1999 jones 13 1600 2000 aron 14 1200 2002
i.e.
ID appreciate some guidance on how to achievesmith 12 1500 2001 jones 13 1600 2000 aron 14 1200 2002
Thank you
Rgdsselect *from (select col1, col2,col3, col4,row_number() over(partition by col1 order by col4 desc) rn from
) where rn=1 -
trigger for update field in a table with the sum of the fields to another table
My experience in creation of triggers and pl/sql in general can be described in terms of oracle with the null value. I practiced by creating arrays and applications on my personal server at home to help me with some of my work related tasks. Right now I am creating a trigger which will, after insert, update, delete on the update of the table assignment_time_track the area of the time_spent on the table of assignments with the sum of the time_spent on the assignment_time_track table fields. I hope that run on the sentence it is clear to the people other than me. I tried this script on my own using the tool of creation of trigger for Oracle Database Express Edition, but I get the following error:
Create a trigger failed, for the following reason:
ORA-06552: PL/SQL: ORA-06553 finished Compilation unit analysis: PLS-320: the declaration of the type of the expression is incomplete or incorrect
Here is my attempt to create the trigger on my own.
create or replace trigger "ASSIGNMENT_TIME_TRACK_T1".
AFTER
INSERT or update or delete on 'ASSIGNMENT_TIME_TRACK '.
for each line
Start
update assignments
Set time_spent = (select sum (time_spent)
of assignment_time_track
where assignment_time_track.name = assignments.name);
end;
/
If what I posted is not clear or more detail is needed, let me know and I will respond with a full description of tables and my goals for each table. Thanks in advance for any help. I also gladly accepts links to tutorials or lessons that explain how to do this kind of thing.
Published by: bobonthenet on March 9, 2009 14:01I think I understand what you mean :)
Rather than use a trigger to keep the master table (assignments) in sync with the time spent on the details, it would be much easier to use a query to do this, maybe creating a view.
Something along the lines of
SQL> create table assignments 2 (id number primary key 3 ,name varchar2(10) 4 ); Table created. SQL> SQL> create table assignment_time_tbl 2 (id number primary key 3 ,assid number references assignments 4 ,time_spent number 5 ); Table created. SQL> SQL> insert into assignments 2 select rownum 3 , 'a' 4 from all_objects 5 where rownum < 5 6 / 4 rows created. SQL> SQL> insert into assignment_time_tbl 2 select rownum 3 , rownum 4 , rownum * 3 5 from all_objects 6 where rownum < 5 7 / 4 rows created. SQL> SQL> commit; Commit complete. SQL> SQL> SQL> select a.id 2 , a.name 3 , (select sum (time_spent) 4 from assignment_time_tbl 5 where assid = a.id 6 ) 7 from assignments a 8 / ID NAME (SELECTSUM(TIME_SPENT)FROMASSIGNMENT_TIME_TBLWHEREASSID=A.ID) ---------- ---------- ------------------------------------------------------------- 1 a 3 2 a 6 3 a 9 4 a 12
-
I can't find the right way to ask a question about the forums themselves.
PAGulley said
I can't find the right part of the forum to ask questions about the forum itself and its features. I wonder what the right place and the way is to get help with the forum system itself. I can find the place to ask questions about specific Mozilla products very well.
Look up where it says contributor tools and select Contributor Forums. Make sure that you scroll to the top or you'll get a bar with different links instead,
The forum is https://support.mozilla.org/forums where you question would be better in the SUMO community discussions.
-
Need help with the installation of an adapter of graphics Super Palit GeForce 9500GT - 512 MB - DDR2 SDRAM in a M2N68 motherboard (narra6). Should I disable the onboard graphics in the bios? When the card is installed, no VGA work outs and the PC does not start. Checked and recontroler implementation of the card in the PCI slot. PC is a desktop HP G5200uk PC. Windows 7 operating system.
Hello
The link below is a guige to install a video card in your Pc. In particular, it seems that you will have to perhaps specify the location of the new card in the bios and save this change before you install the new card - see step 4 in the guide on the link below. If your new card fits into the PCI Express x 16 slot, you will need to define PCI Express in the bios and save the changes.
http://support.HP.com/us-en/document/c01700855
Kind regards
DP - K
-
help with the beats on my envy 17-3270nr, n key
help with the beats on my envy 17-3270nr key. recent Smart hard disk crash, replaced with exact same hitachi drive, same care extended warranty repairs covered of the Frys. Windows 7 Edition home premium w / service PAC 1 installed, drivers installed, except that now there is no volume of beats on screen graphic dial button, click the button on top button on the page does not call the beat of the application settings. Futhermore; the motion sensors of laser to activate the keyboard backlit keyboard do not work. Are there drivers hp software to enable the missing features?
Hello
Download and install the following.
Once completed, restart the laptop.
Kind regards
DP - K
-
I need help with the program of Photos on my macbook pro
I use a Macbook Pro with OS of Yosemite. I really need help with the Photo program. I never really got the hang of IPhoto and now that it's a new program, I'm really confused. Where can I go to learn this without waiting for the next workshop in a local store?
Hi, I'm fighting to open same mine, making a new software update
-
Help with the Powershell script to collect logs from all domain controllers
I am writing a script to retrieve the last 5 days of application, security and log files from all domain controllers. The script runs, but fire the logs from the local server only. The variable $Computer has all of my DC so it's the fine mark. I guess it's a problem with my line ForEach-Object, but is not error. See the below script.
$log = 'application '.
$date = get-date-format MM-DD-YYYY
$now = get-date
$subtractDays = new-object System.TimeSpan 5,0,0,0,0
$then = $Now.Subtract ($subtractDays)
$Computers = get-ADDomainController-filter *.
ForEach-Object - InputObject $Computers - process {Get-EventLog - LogName $log - after $then - before $now - EntryType error | select EventID, MachineName, Message, Source, TimeGenerated |} ConvertTo-html | {Out-file $env:TEMP\Applicationlog.htm}
Invoke-Expression $env:TEMP\Applicationlog.htmThank you
Rich
Hello
To help with the repost the question script to the script Center Forum
http://social.technet.Microsoft.com/forums/scriptcenter/en-us/home
-
Need help with the launching track pack for forza code 4
Bought new Forza 4 and the lancer Track Pack code does not work, how do I get a code that is generated in the form I've already paid for it. Rank of loads of numbers and sent 10 s of emails but cant seem to get help.
This is the help I get when the cat to an Ambassador xbox on xbox.com
Terry wrote:Need help with the launching track pack for forza code 4The Xbox Ambassador says:Location of Ambassador of the community...The Xbox Ambassador says:Location of Ambassador of the community...The Xbox Ambassador says:Your question will be answered by an Ambassador of the Xbox. You have been connected to the Ambassador as a user Xbox [3]The Xbox Ambassador says:HelloTerry wrote:HelloThe Xbox Ambassador says:HeyTerry wrote:just to be on the phone to xbox live support and was told to come hereThe Xbox Ambassador says:ok\The Xbox Ambassador says:What is your problem?Terry wrote:I bought the 4 for forza ansd 360 new sealed Christmas...Terry wrote:has got 2 codes that accompanies the game but the pack track code does not workThe Xbox Ambassador says:Wow goodTerry wrote:whenever I put in the code it says code redeemedThe Xbox Ambassador says:I think the code is used. You must return to the retailerTerry wrote:I tried to, but since I already opened the case they will not acceptThe Xbox Ambassador says:Oh. No,Terry wrote:the code had been used or defective as I am the only person who has touched the game once opened, tried to enter the code when it is openThe Xbox Ambassador says:Maybe it was auto bought?Terry wrote:so, how do I get another code generated track Pack if defective?The Xbox Ambassador says:I do not know.Terry wrote:bought the game new, so I get the track packThe Xbox Ambassador says:Oh. It's bad.The Xbox Ambassador says:I think that if you Exchange 1 code it will buy itTerry wrote:car pack code worked, starter pack did not workThe Xbox Ambassador says:Oh.The Xbox Ambassador says:It's a badThe Xbox Ambassador says:BTW you have an evolution of the tests?Terry wrote:Yes, I want to? but more anxious to get a code object generated for this packThe Xbox Ambassador says:Hey if I help can u give me this game too?Terry wrote:?????????????????Terry wrote:So is it possible to get a code for that time?The Xbox Ambassador says:HeyThe Xbox Ambassador says:Yes.The Xbox Ambassador says:you need to contact themThe Xbox Ambassador says:and tell them that the code is used.Terry wrote:I was told to come here? where can I go to get the code?Hi Terryg76,
· What version of the operating system is installed on the computer?
I suggest you to contact the game manufacturer for more help and information.
-
Original title: need help with the blue screen issue
My computer turns saying a blue screen: a problem has been detected and windows were shut down to prevent damage. The problem seems to be caused by the following file: NAVEXI5. SYS PAGE_FAULT_IN_NONPAGED_AREA he seems to have a different error whenever he turns to a blue screen. Can someone help me please.Hello
1. Since when are you facing this problem?
2. you remember to make changes to the system?
3. do you get an error with this error code?I suggest to unplug external devices such as printer, scanner, etc. that are plugged into the system, and then restart the system and check if the problem persists.
Method 1.
I suggest you to do a check disk from the recovery console and check if the problem is resolved. Follow the steps mentioned below.
a. start into the recovery console using the XP CD. Follow the steps mentioned in the article below.
Description of the Windows XP Recovery Console for advanced users
http://support.Microsoft.com/kb/314058
b. perform a disk check.
How to perform disk error checking in Windows XP
http://support.Microsoft.com/kb/315265Method 2.
I suggest you to start with the XP CD and then do a system restore. Follow the steps mentioned in the article below.
How do I recover from a corrupted registry that prevents Windows XP startup
http://support.Microsoft.com/kb/307545I hope this helps.
-
Help with the part number - paw index screen X230ti
Can anyone help with the reference number and or the availability of the small 'legs' that sit in the slots on each side of the keyboard on a X230ti? They locate into the slots with the screen and prevent movement when the lid is closed.
I have the same and among the small beasts broke and the screen tends to rotate when closed.
Have searched for a parts list but cannot find the "paw" in any list that I found. Thank you
Here is a picture of the X230t keyboard (and palmrest) framework. You can see the small 'legs' to belong to him.
I hope someone from Lenovo will tell you how to order this part. EDIT: part number 04W6808.
-
Help with the purchase of a microSDHC
I recently filled my Fuze, upgraded to the latest firmware and I'm ready to increase its capacity. I thought to buy a 8 GB Sandisk from amazon, but I'm not if I need a SD adapter so I can connect it to my computer. If I keep it plugged the "rocket" I will be able to access the card through the device, or it will appear as a separate storage device? Any help with the purchase of a microSDHC will be greatly appreciated.
The 8 GB SanDisk microcard works perfectly, and you can plug just the "rocket" and most likely to leave it there. When you connect to your computer the microcard will appear as a separate... drive for example, on mine, the "rocket" is the J: drive and the card is drive K:
Anything on the card will be perfectly integrated into the memory of the "rocket" when using it.
-
Please help with the problems of Vista SP2
So I spent all day on the forums here and I'm head over heels. I had problems with Windows update and some other problems on my Dell Studio XPS. It is a tower with double HDs in RAID mirror running Vista 64-bit with SP2.
I got it for 3 years and I thought that I clean and correct certain defects to go back to the original Dell factory condition. That did not fix the update install problem I did cleaning. Now it's worse.
I'm trying to install SP2 and get a catastrophic failure 0x8000ffff error-UNEXPECTED
The onlychange is that several months ago, one of my WD 640 GB drives factory failed and I replaced it with a Seagate Barracuda 1 TB since I couldn't find a 640 GB drive.
I tried to stop and restart all services BITS, etc. no luck.
I tried to run among the MS FixIt for the problem of update, but it fails because it says that it cannot initialize the powershell.
Help, please... I'm hopelessly lost and can not spend more money on this thing.
Thank you!
If you need additional help with the clean install, please start your own, new topic in this forum: http://answers.microsoft.com/en-us/windows/forum/windows_vista-system
If these procedures look too complex - and there is no shame in admitting this isn't your cup of tea - take the machine to a local, good reputation and independent (i.e., not a BigBoxStore or a Geek Squad) computer repair shop & ask them to do the job.
Maybe you are looking for
-
Satellite T110-13R wireless card won't be connected
Hello After manually installing windows 7 32 bit on my satellite T110-13R after formatting drive C:, my wireless card does not want to connect, and fn + f8 does not work. The wireless card appears in the device management, but does not connect and no
-
Media Player: some counties of playlist and missing lengths
To view my playlists, I chose the columns 'title', 'count' and 'length '. Most of my playlists shows this information, but many display only "title". This is more common on the newly added playlists. Sometimes missing information suddenly appears
-
I just got a phone call from 282-726-2524. The person claims to be calling on behalf of Mircosoft Windows wanting to make changes to the system on my personal PC. Of course I told her 'NO '. Who should be reported?
-
I want to download Adobe Acrobat 3D Version 8 but cannot find the link to download anywhere on your site. Could anyone refer me please to the location of the 3D Acrobat full download? [E-mail removed by Moderator]
-
Why won't my email form send me an email?
I have a Contact Me pages built in the Muse and computing appear to be installed correctly, but when you go to my site and enter your e-mail information, I do not get the form sent to me. Any ideas or recommendations?