MODEL/PIVOT: Help pls
Hello
I'm trying to convert rows into columns using model/Pivot in Oracle 11 g. Please find the details below.
CREATE TABLE TEST_DATA_FIN
(NUM NUMBER (9),)
ID NUMBER (9),
YEAR NUMBER 4.
NUMBER VALUE (9.2))
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2014, 1);
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2014, 2);
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2014, 3);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2014, 4);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2014, 5);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2014, 6);
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2013, 7);
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2013, 8);
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2013, 9);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2013, 10);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2013, 11);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2013, 12);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2013, 13);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2013, 14);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2013, 15);
INSERT INTO TEST_DATA_FIN
VALUES (2,200,2013, 16);
INSERT INTO TEST_DATA_FIN
VALUES (2,200,2013, 17);
INSERT INTO TEST_DATA_FIN
VALUES (2,200,2013, 18);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2012, 19);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2012, 20);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2012, 21);
INSERT INTO TEST_DATA_FIN
VALUES (2,200,2012, 22).
INSERT INTO TEST_DATA_FIN
VALUES (2,200,2012, 23);
INSERT INTO TEST_DATA_FIN
VALUES (2,200,2012, 24);
For Ex,.
NUM = 1
IF MAX (YEAR) = 2014
then a query that returns
new columns
NUM,
ID,
YEAR
YEAR1_DATA with 1,
YEAR2_DATA with 2,
YEAR3_data with 3 and so on...
For ex:
NUM = 2
IF MAX (YEAR) = 2013
Then, the query must return
new columns
NUM = 2,
ID,
YEAR1_DATA 13,
YEAR2_DATA 14,
YEAR3_data with 15 and so on...
The final output should be in the following format. Has managed to implement in Decode/Group by. I am trying to write a query using MODEL/PIVOT.
You can help me pls.
NUM YEAR ID YEAR1_DATA YEAR2_DATA YEAR3_DATA
--------------------------------------------------------------------------------------------------
1 100 2014 1 2 3
1 200 2014 4 5 6
1 100 2013 7 8 9
2 200 2013 10 11 12
2 100 2013 13 14 15
2 200 2013 16 17 18
2 100 2012 19 20 21
2 200 2012 22 23 24
Thank you very much. I really appreciate any help.
Hello
946141 wrote:
Thank you very much for your answers. I messed up the data bit. Very sorry about that.
With the following data.
Max (Year) value should go in YEAR1_DATA and MAX (YEAR) - 1 value should go in YEAR2_DATA.
I am sorry once again and appreciate your help.
The output should be as follows
DIGITAL ID YEAR1_DATA YEAR2_DATA YEAR3_DATA
---------------------------------------------------------------------------------------
1 100 33333 22222 11111
1 200 44444 66666 55555
2 100 333333 222222 111111
2 200 4444444 666666 555555
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2014, 33333);
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2013, 22222);
INSERT INTO TEST_DATA_FIN
VALUES (1,100,2012, 11111);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2014, 44444);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2013, 66666);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2012, 55555).
-----------------
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2013, 333333);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2012, 222222);
INSERT INTO TEST_DATA_FIN
VALUES (2,100,2011, 111111);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2013, 4444444);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2012, 666666);
INSERT INTO TEST_DATA_FIN
VALUES (1,200,2011, 555555);
I think you want something like:
WITH got_r_num AS
(
SELECT num, id, value
, MAX (year) OVER (PARTITION BY num, id)
-r_num year
OF test_data_fin
)
SELECT *.
OF got_r_num
PIVOT (MIN (value)
FOR r_num IN (0 AS year1_data
1 AS year2_data
2 UNDER year3_data
)
)
ORDER BY num
, id
;
I don't see how you get the output you posted form data in the sample. Will there be some typos in one or the other?
For example, in the sample data, 100 is the only id associated with num = 2, so I don't understand the output line that is num = 2 and id = 200. I'm guessing that there is a mistake somewhere.
Tags: Database
Similar Questions
-
my laptop keyboard is not working. His pavilion G6 2228TU model please help me.
my laptop keyboard is not working. His pavilion G6 2228TU model please help me.
Hello
This could be a hardware problem, but it is always worth trying the following.
Open windows control panel, open Device Manager, expand keyboards, "Standard PS/2 Keyboard" right click and select uninstall.
When you are finished, stop the laptop - if you're running Windows 8 or 8.1, do it by holding down the button SHIFT left click Shutdown to temporarily prevent a hybrid boot.
Then disconnect the AC adapter and then remove the battery. Press and hold the Power button for 30 seconds. Reinsert the battery and plug in the AC adapter.
Robinet tap away at the key esc that you start the computer to launch the Start Menu, and then select f10 to open the bios menu. Press f5 to load the default values (sometimes it's f9, but the menu below indicates the correct key), use the arrow keys to select 'Yes' and press ENTER. Press f10 to save the setting and still use the arrow keys to select 'Yes' and press on enter.
Kind regards
DP - K
-
I forgot my own computer admin and password... How to reset help pls
I forgot my own computer admin and password... How to reset help pls
Sorry, but we are not allowed to help you with that. Contact your local computer repairer and get them to break.
-
I don't see the icon of mail in the Panel, I need this to configure outlook express help pls
I don't see the icon of mail in the Panel, I need this to configure outlook express help pls
Hello
1. are you referring to Windows mail or Outlook Express?
2 have you made changes on the computer before this problem?
3 What is a 32-bit or a 64-bit operating system?
Try the next method and check if it helps.
Method 1:
Step 1:
Change the setting from Control Panel and check if that helps.
a. Click Start, then select Control Panel
b. click on additional Options
c. Select view 32-bit Control Panel items and click on Mail and check if that helps.
Step 2:
Change the display panel and check if it helps
a. go to control panel,
b. click view classic iconsSee also:
http://Windows.Microsoft.com/en-us/Windows-Vista/where-is-Outlook-Express
-
can someone help me while I install windows 7 I got massage that windows did not read my DVD my lap top hp probook 4540 i5 s any help pls
Hi, Ahmed.
Have you tried using a different DVD?
I would also create a USB support and then try to install.
Take a look at this-
http://www.microsoftstore.com/store/msusa/HTML/pbPage.Help_Win7_usbdvd_dwnTool
To let us know.
-
The 413 header length too large. How can I install flash player? Because when press the link 413 header length too large can help pls. Thank you
Hello
Please clear the browser's cache and cookies or remove the *. Adobe.com items in your list of cache and cookies of browsers. The installer will then download.
--
Maria
-
Hey guys, ive tryied buy photoshop like a hundret times, ive typed in my information payment and everything I need, went on the button pay on the accept button but nothing happened, I need help pls passing sry for my language
Contact adobe during the time pst support by clicking here and, when available, click on "still need help," http://helpx.adobe.com/x-productkb/global/service-ccm.html
-
can someone help pls. I would like to create a rectangle with a sharp angle and have no idea how. the brown box, is I want what he's watching.
Use the direct selection (white arrow) to select the right angle lower (or higher) and drag it where you want it to be.
-
SM bus controller driver cannot install help pls
Hello Sir/Madam,
kindly pls help me with my problem of software. I can't install my sm bus controller on my
ENVY 23 HP ALL IN ONE PC.
Model No. 23 - 1068hk
product no. H3TT77AA
Serial No. (personal information)
I am here now in the philippines, I buy my computer in Hong Kong Macau.
I reformat my computer to install a new windows7 ultimate.
Heres my screenshot
http://i1117.Photobucket.com/albums/K583/oyekvillanueva/Screenshot10h59m34s.jpg
Hi oyekvillanueva
Intel Chipset driver
-
The parallel model configuration help
This is my first time posting, but I'm a long time reader...
First of all, I consider my knowledge novice Teststand high to low intermidiate level. I created a sequence test to aid in Teststand that call labview vi. My test sequence tests 5 units at a time in a parallel model (model in parallel sequence). From a functional point of view, everything works great for single pass and loops. However, here's my problem:
When you select "USE Test", it brings up a window that asks you the serial number for each of the five stations. The operator must then enter a serial number for each and press OK proceed. This configuration is not valid for what I do. My test setup has a button for each of the 5 stations. The user must press the button to start the test (connects to a data acquisition). Then the serial number is read from the UUT and entered in the report.
How could I go how to reconfigure it? I'm not looking for someone solve my problems for me, I just need a little direction. I looked at the parallel sequence model and I may not know where to go with it.
Help, please
Ryan
TestStand 4.2
LabVIEW 2009
In the parallel model, you will see the Pre DUT reminder. Inside of there, you will find the steps that call the dialog box you're talking about. The best option is to replace it in your file of the client's sequence. Then write your own code that dictate the required operators to go direction.
It's just the description the General "point you in the right direction." Please let me know if you want more details.
Kind regards
-
World of warcraft WOTLK patch 3.2 ui is missing... help pls
OMG someone help me pls pls pls pls I reinstalled the game 4 times in the last 24 hours and then execute and apply what seams like 1 million hours of updates only to prevent haing appon question investigation I found that the drivers for my Dell Latitude D380 must 09 pilots run this current fix I can't find them anywhere I am using 32-bit vista buissness I went to the dell site, they only offer drivers since 2008 I can't know how to resolve this its driving me crazy I am a gm and I can't get online sort Guild questions can you give me a help link or do I
name of the device mobile Intel (r) 965 express Chipset Family (current display mode 1680 x 1050 (32 bit) (60 Hz))
driver main igdum32.dll version (in English) 7.14.0010.1409 Date 01/02/2008 WHQL Logo would be Yes 9Ex DDI versionIf anyone can help sort that you are a champion frecking masculine amounst God... ty all in advance
Hello Dragondojin,
Are you sure that you have a Latitude D380 and not a D830. I have not found a listing for a D380. I have included a link to the drivers for the D830 page just in case it was a typo. If you can find the updated drivers here, then you can be out of luck.
You can also search the video card drivers updated directly on the manufacturer support site like intel or nvidia.com.
Try this out and let me know the results.
P.S. I really can't see how a GM could apply a patch without because that test first, that if you are hosting a private server.
I have a simple philosophy: just assume everyone is a piece of _ and then be pleasantly surprised if you find someone who is not.
-
Outlook Express won't help pls open suddenly.
I just turned on my PC and my OE does not open, the first message that appears is tells me memory or drive may be full, which is not the case, with a code of Ox800Co13B, the other tells me that OE is unable to start because the file MSOE. DLL cannot be initialized. The version I have is OE 6.0 and Windows 8. Nothing has been changed or installed. It was working when I turned off last night and it works tonight, and that's what's happening. I'm no tech at all, so I have no idea how to get my e-mail program open now. I have so many things in there, I have and I am freaked. Pls. any help would be greatly appreciated. Since I can not in it, if there is a response back, due to the lack of work e-mail program, I'll keep checking back. Thank you all in advance.
BAK files are backup OE files. They have something to do with OE.
You don't have Inbox.bak or Webfire Inbox.bak files anywhere? You posted this earlier:
Deleted items dbx. The DBX file 187 KB (all are now showing modified as today is the date)
Dbx air currents. File DBX 59KO
The dbx files. File DBX 74KO
Inbox dbx. DBX 122 365 KB file
Dbx in offline mode. File DBX 10 KB
Outbox of dbx. File DBX 187KO
Dbx Pop3uidl. File DBX 10 KB
Dbx to sent items. DBX 1 188 KB file
WebFIRE 37 845 KB Inbox.dbx DBX fileDo you have still the Inbox.dbx file and the Webfire Inbox.dbx file in the message store, or on the desktop if you did who?
If they are still in the message store, rename them, and then drag them to the desktop.
I'm sorry, but with all the bak files, or your own backup, it is the only tool that has a chance to recover the messages of these files
DBXpress:
http://www.oehelp.com/DBXpress/default.aspxThere's no other way.
You may need to run in the extract from disk Mode if its normal recovery mode fails to find lost messages.
Bruce Hagen MS - MVP [Mail]
-
Help Pls, same map graphic, but different brand works on my PC
I was told to come back on the HP forum to see if my PC can use other brands of graphics card I have a HP Pavilion p6109uk desktop PC
& my graphics card is HP - 586382 - 001 - Sps - Pca Oribi D10m1 GeForce G210 512 MB
but this map graphic is to play so I want to replace it for the same thing but HP - 586382 - 001 - Sps - Pca Oribi D10m1 GeForce G210 512 MB cost too expensive at £ 90.00 to £130.00 but these below cost less but they are working on my machine and if they aren't which can make...
Here are the other graphics card I have described here at a lower price;
PNY 512 MB GeForce G210 GDDR2 price £25.00 NVIDIA graphics card
ASUS Nvidia GeForce G210 512 MB DDR2 Low Profile HDMI SILENT price £28.00
Gigabyte Nvidia Geforce G210 512 MB Gddr2 64 - bit Hdmi Dvi Pci - e Lp... price £39.99
NVIDIA GeForce G210 1024 MB / 1 GB 64 - bit DDR3 PCI-E DVI VGA HDMI... price £29,29
And here are my PC Specs:-
Intel Core 2 Quad Q8200
Windows Vista Home Premium Edition SP2 (Build 6002)
CPU Arch: 1 CPU - 4 hearts - 4 wire
PSN CPU: Intel Core 2 Quad CPU Q8200 2.33 GHz
CPU EXT: MMX, SSE (1, 2, 3, 3, 4.1), EM64T
CPUID: 6.7.A / Extended: 6.17
CPU cache: L1: 4 x 32 / 4 x 32 KB - L2: 2 x 2048 KB
Core: Yorkfield (45 nm) / Stepping: R0MB brand: PEGATRON CORPORATION
Model MB: Eureka3
NB: Rev of Intel P45/P43/G45/G43 A3
SB: Intel 82801IR (ICH10R) rev 00
Type GPU: NVIDIA GeForce G210
GPU clocks: 589 MHz Core / 499 MHz RAM
DirectX Version: 11.0
RAM: 4096 MB DDR3 Dual Channel
RAM speed: 532 MHz (5:8) @ 7-7-7-20
Slot 1: 2048 MB (10700)
Slot 1 manufacturer: Samsung
Slot 2: 2048 MB (10700)
Slot 2 manufacturer: SamsungPower supply 350W
PCI Express x 16
Pls know me if other info is necessary because I'm a noobTHANKS!
Here are the specifications of your HP p6109uk desktop. According to specifications, your computer comes with a 300 Watt power supply. You say in your post that the power supply is 350 Watts. Please check the rating of your diet.
It seems that any replacement replacement cards that you listed should work in your system.
Good luck.
Frank
-
BlackBerry Smartphones aggggghhh HELP PLS!
OK, I have a curve 8530 & I've had this problem for a few days now and its really starting to tick me! I can't get my backlight turns off as it allows. It stays on permanently! I went to the settings and nothing works! Its my battery drainage and very annoying! Pls help!
Do a simple reboot on the BlackBerry this way:
With the BlackBerry powereddevice, remove the battery for a minute and then reinsert the battery to restart. A reboot in this way is prescirbed for most the gltiches and operating system errors, and you will lose any data on the device doing so.
Now, once restarted, see how the backlight.
-
Photoshop will not uninstall! help PLS
Hello! , recently my photoshop has started giving me an error code: '1'... tried everything to implement, but I couldn't fix it. So I tried to uninstall "Photoshop"... thinking that might solve the problem... but there is another problem! I can't uninstall even my Photoshop!... It gives me this error: http://prntscr.com/9y734p (ScreenShoot) I tried their utmost to repair and I even used the cleaning tool, but it doesn't help...
Pls help me solve this problem...
Hi Faisals14348980,
Please follow the steps below:
1 complete the process / Task Manager tasks in the same order, as mentioned below the Manager tasks. See, Open the Task Manager
- Creative cloud
- Basic timing & sync to basic support
- CC library & process CCX
- Adobe Common Desktop
- Adobe update daemon
- Broker CIB Adobe
- After that, everything that said adobe on it do a force quit for her
2 remove the rest of the files: ( If you do not see any folder skip this step )
C:\Program Files \Common Files\Adobe\Photoshop
C:\Program Files \Adobe\Photoshop
C:\Users\
\AppData\Local\Adobe\ MAA UPDATER and OOBE ( App data & Program Data is hidden folder please see, Show files and folders hidden in Windows 7, 8.x, 10, or Vista) Let us know if that helps.
Maybe you are looking for
-
Can I create a message for my outgoing messages filter?
I'm working on a big project with many people. I created a mail filter to send all my incoming emails project in a designated folder. There are a lot of emailing every day, and it would be a help I could get my messages OUTGOING filtered directly in
-
I need help to reinstallation of XP in a new computer...
I need help to install XP on a new computer... Mircrosoft says it's a matter of tech...I changed the bios to boot from the cd, but the part of the installation is shaded, as in not available for installation.Can anyone help?The computer is a toshiba
-
My application does not work on storm and torch
So, this morning, one of my colleagues came to my office to show me that he got a BB Torch and man, the thing is pretty sexy! Well, the thing is, he asked me to install my application on her bb and what was my surprise, he worked... Well, it installe
-
Smartphones blackBerry e-mail account setting
Hello everyone, Im trying to set an account * @gmail.com. My BB 9900 shows: "activation request failed. A service connection is unavailable. "At the same time an Im surfing all websites through the device. Please notify. Thank you very much. -DM
-
How to add photos from the computer on the BB 8520 curve BlackBerry Smartphones?
I wonder how can I add images to my computer on my BB Curve 8520. Any ideas?