Solution to a complex problem (not to let him die, answer)
I have two table with the structure below
MASTER_PARAM | Data type |
PARAM_ID | NUMBER |
PERIOD_FROM | DATE |
PERIOD_TO | VARCHAR2 (10 byte) |
PRIORITY | NUMBER |
UPLOAD_VALUE | NUMBER |
PARAM_DETAIL | Data type |
PARAM_DTL_ID |
NUMBER
PARAM_ID
NUMBER
MODEL_ID
VARCHAR2 (10 byte)
PROFIT_CENTER_ID
NUMBER
DEALER_ID
NUMBER
Now my goal is to insert records into the table Master_Param and Param_detail (for a table of the given source) under the following conditions
(1) for a Model_id - combination of dealer _ID (present in the source table) if the file is already there for the given date range and priority, then the Master_Param be, and the upload_value column will be updated accordingly.
(2) for a Dealer_id model_id if recording isn't here for a given date range and priority was a new record should be inserted to the table with a new param_id Master_Param and later param_detail table must be completed (for the same param_id as it is a foreign to this table key) and model_id-dealer_id information should be inserted in the table come.
Say the source table contains records in the format below
Source_table | ||
Date_From | DATE_TO | MODEL_ID |
Dealer_ID
Upload_value
PRIORITY
April 1, 13
30 April 13
1000
11
12
1
April 1, 13
30 April 13
1001
11
20
1
April 1, 13
30 April 13
1002
11
30
1
April 1, 13
30 April 13
1000
12
25
1
April 1, 13
30 April 13
1005
12
21
1
Before insertion | |||||
MASTER_PARAM | |||||
PARAM_ID | PERIOD_FROM | PERIOD_TO | PRIORITY | UPLOAD_VALUE | |
1 | April 1, 13 | 30 April 13 | 1 | 10 |
2
April 1, 13
30 April 13
1
10
3
April 1, 13
30 April 13
1
20
4
February 1, 13
28 February 13
1
25
For every param_id there is a matching record in the secondary table
PARAM_DETAIL | |||
PARAM_DTL_ID | PARAM_ID | MODEL_ID | DEALER_ID |
101 |
1
1000
11
102
2
1003
14
103
3
1002
11
104
4
1001
11
After Insertion | |
MASTER_PARAM |
PARAM_ID
PERIOD_FROM
PERIOD_TO
PRIORITY
UPLOAD_VALUE
1
April 1, 13
30 April 13
1
12
Update
2
April 1, 13
30 April 13
1
10
3
April 1, 13
30 April 13
1
30
Update
4
February 1, 13
28 February 13
1
25
5
April 1, 13
30 April 13
1
20
Inserted
6
April 1, 13
30 April 13
1
21
Inserted
PARAM_DETAIL |
PARAM_DTL_ID |
PARAM_ID
MODEL_ID
DEALER_ID
101
1
1000
11
102
2
1003
14
103
3
1002
11
104
4
1001
11
105
5
1001
11
Inserted
106
6
1005
12
Inserted
Insert multi table and simple update statement will satisfy your requirement.
Here is the illustration with your sample data.
SQL >
SQL > select * from v version $;
BANNER
--------------------------------------------------------------------------------
Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
PL/SQL Release 11.2.0.2.0 - Production
CORE Production 11.2.0.2.0
AMT for Linux: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
SQL >
SQL > DROP SEQUENCE param_id_seq;
Sequence has fallen.
SQL > DROP SEQUENCE param_dtl_seq;
Sequence has fallen.
SQL > DROP TABLE source_table;
Deleted table.
SQL > DROP TABLE param_detail;
Deleted table.
SQL > DROP TABLE master_param;
Deleted table.
SQL > CREATE SEQUENCE param_id_seq
2. START BY 5
3 MAXVALUE 999999
MINVALUE 4 0;
Order of creation.
SQL > CREATE SEQUENCE param_dtl_seq
2. START WITH 105
3 MAXVALUE 999999
MINVALUE 4 0;
Order of creation.
SQL > CREATE TABLE master_param
() 2
3 param_id NUMBER PRIMARY KEY,
4 period_from DATE,
5 period_to VARCHAR2 (10 BYTE),
6 priority NUMBER,
7 upload_value NUMBER
8 );
Table created.
SQL > CREATE TABLE param_detail
() 2
3 param_dtl_id NUMBER PRIMARY KEY,
NUMBER of REFERENCES of param_id 4 master_param (param_id),
5 model_id VARCHAR2 (10 BYTE),
6 profit_center_id NUMBER,
7 dealer_id NUMBER
8 );
Table created.
SQL > CREATE TABLE source_table
() 2
3 date_from DATE,
4 date_to VARCHAR2 (10),
5 model_id VARCHAR2 (10 BYTE),
6 dealer_id NUMBER,
7 upload_value NUMBER,
8 priority
9 );
Table created.
SQL >-load sample data into master_param
SQL > INSERT INTO master_param
2. SELECT *.
3 FROM (SELECT 1 AS param_id,
4 TO_DATE ('1 April 13', 'DD-MON-YY') AS period_from,
5 30 April 13 ' AS period_to.
6 1 priority,
7 10 AS upload_value
8 DOUBLE
9 UNION ALL
10. SELECT 2 AS param_id,
11 TO_DATE ('1 April 13', 'DD-MON-YY') AS period_from,
12 30 April 13 ' AS period_to.
13 1 priority,
14 10 AS upload_value
15 DOUBLE
16 UNION ALL
17 SELECT 3 AS param_id,
18 TO_DATE ('1 April 13', 'DD-MON-YY') AS period_from,
19-30 April 13 ' AS period_to.
20 1 priority,
21-20 AS upload_value
22 DOUBLE
23 UNION ALL
24 SELECT 4 AS param_id,
25 TO_DATE ('1 February 13', 'DD-MON-YY') AS period_from,
26-28 February 13 ' AS period_to.
27 1 priority,
28 25 AS upload_value
29 FROM DUAL) temp;
4 lines were created.
SQL >-load sample data into Param_detail
SQL >
SQL > INSERT INTO param_detail
2. SELECT *.
3 FROM (SELECT 101 AS param_dtl_id,
4-1 AS param_id,
5 1000 AS model_id,
6 NULL AS profit_center_id,
7-11 AS dealer_id
8 DOUBLE
9 UNION ALL
10. SELECT 102 AS param_dtl_id,
11 2 AS param_id,
12 1003 AS model_id,
NULL AS profit_center_id 13,
14 14 AS dealer_id
15 DOUBLE
16 UNION ALL
17 SELECT 103 AS param_dtl_id,
18 3 AS param_id,
19 1002 AS model_id,
20 NULL AS profit_center_id,
21-11 AS dealer_id
22 DOUBLE
23 UNION ALL
24 SELECT 104 AS param_dtl_id,
25 4 AS param_id,
26 1001 AS model_id,
NULL AS profit_center_id 27,
28-11 AS dealer_id
29 FROM DUAL) temp;
4 lines were created.
SQL >
SQL >
SQL >-load sample data in table_source
SQL >
SQL > INSERT INTO source_table
2. SELECT *.
3 (SELECT TO_DATE ('1 April 13', 'DD-MON-YY') AS date_from,)
4 30 April 13 ' AS date_to,.
5 1000 AS model_id,
6-11 AS dealer_id,
7 12 AS upload_value,
8 1 priority
9 DOUBLE
ANY UNION 10
11 SELECT TO_DATE ('1 April 13', 'DD-MON-YY') AS date_from,.
12 30 April 13 ' AS date_to,.
13 1001 AS model_id,
14 11 AS dealer_id,
15-20 AS upload_value,
16 1 priority
17 OF THE DOUBLE
18 UNION ALL
19 SELECT TO_DATE ('1 April 13', 'DD-MON-YY') AS date_from,.
20-30 April 13 ' AS date_to,.
21 1002 AS model_id,
22 11 AS dealer_id,
23-30 AS upload_value,
24 1 priority
25 DOUBLE
26. ANY TRADE UNION
27 SELECT TO_DATE ('1 April 13', 'DD-MON-YY') AS date_from,.
28-30 April 13 ' AS date_to,.
29 1000 AS model_id,
30 12 AS dealer_id,
31 25 AS upload_value,
32 1 priority
33 OF THE DOUBLE
34. ANY TRADE UNION
35 SELECT TO_DATE ('1 April 13', 'DD-MON-YY') AS date_from,.
36 30 April 13 ' AS date_to,.
37 1005 AS model_id,
38 12 AS dealer_id,
39 21 AS upload_value,
40 1 priority
41 DOUBLE) temp;
5 rows created.
SQL >
SQL > COMMIT;
Validation complete.
SQL >
SQL >-table insert Multi
SQL >
SQL > INSERT ALL
2 IN master_param (param_id,
period_from 3,.
period_to 4,.
priority 5,
6 upload_value)
7 VALUES (param_id_seq. NEXTVAL,
date_from 8.
date_to 9,.
priority 10,
11 upload_value)
Param_detail (param_dtl_id 12,
param_id 13,
model_id 14,
15 dealer_id)
16 VALUES (param_dtl_seq. NEXTVAL,
17 param_id_seq. NEXTVAL,
model_id 18,
19 dealer_id)
Date_from SELECTION 20,
date_to 21,
model_id 22,
dealer_id 23,
upload_value 24,
25 priority
26 OF source_table st
27. WHERE DOES NOT EXIST
28 (SELECT 1
29. OF master_param a, param_detail b, c from source_table
30 WHERE a.param_id = b.param_id
31 AND b.model_id = c.model_id
32 AND b.dealer_id = c.dealer_id
33 AND a.period_from = c.date_from
34 AND a.period_to = c.date_to
35 AND a.priority = c.priority
36 AND st. ROWID = c.ROWID);
6 rows created.
SQL >
SQL > COMMIT;
Validation complete.
SQL >
SQL > SELECT * FROM master_param;
PARAM_ID PERIOD_FR PERIOD_TO PRIORITY UPLOAD_VALUE
---------- --------- ---------- ---------- ------------
April 1 1 13 30 April 13 1 10
April 2 1 13 30 April 13 1 10
April 3 1 13 30 April 13 1 20
February 4 1 13 February 28 13 1 25
April 5 1 13 30 April 13 1 20
April 6 1 13 30 April 13 1 25
April 7 1 13 30 April 13 1 21
7 selected lines.
SQL >
SQL >
SQL >
SQL > UPDATE master_param mp
2 SET upload_value =
3 (SELECT c.upload_value
4. FROM master_param a, param_detail b, c from source_table
5 WHERE a.param_id = b.param_id
6 AND b.model_id = c.model_id
7 AND b.dealer_id = c.dealer_id
8 AND a.period_from = c.date_from
9 AND a.period_to = c.date_to
10 AND a.priority = c.priority
11 AND a.param_id = mp.param_id)
12. WHERE THERE IS
13 (SELECT 1
14. FROM master_param a, param_detail b, c from source_table
15 WHERE a.param_id = b.param_id
16 AND b.model_id = c.model_id
17 AND b.dealer_id = c.dealer_id
18 AND a.period_from = c.date_from
19 AND a.period_to = c.date_to
20 AND a.priority = c.priority
21 AND a.param_id = mp.param_id);
5 lines to date.
SQL >
SQL > COMMIT;
Validation complete.
SQL >
SQL > SELECT * FROM master_param;
PARAM_ID PERIOD_FR PERIOD_TO PRIORITY UPLOAD_VALUE
---------- --------- ---------- ---------- ------------
April 1 1 13 30 April 13 1 12
April 2 1 13 30 April 13 1 10
April 3 1 13 30 April 13 1 30
February 4 1 13 February 28 13 1 25
April 5 1 13 30 April 13 1 20
April 6 1 13 30 April 13 1 25
April 7 1 13 30 April 13 1 21
7 selected lines.
SQL >
SQL > SELECT * FROM param_detail;
PARAM_DTL_ID PARAM_ID PROFIT_CENTER_ID DEALER_ID MODEL_ID
------------ ---------- ---------- ---------------- ----------
101 1 1000 11
102 2 1003 14
103 3 1002 11
104 4 1001 11
105 5 1001 11
106 6 1000 12
107 7 1005 12
7 selected lines.
SQL >
SQL > spool off;
Thank you
GPU
Tags: Database
Similar Questions
-
I can't get my autoblogging software to run on Vista. I know it works with vista, because other users have on their machines. The developer also said it works on vista very well.
For some reason, it does not work on my machine. I installed 2 different versions of the software and both give me error in the title of this thread immediately. He doesn't have the ability to load up and fail or anything he just lift the error immediately.
for purposes of test and restore my sanity a little I have installed this software on an old laptop running XP and a desktop running xp, after installing the software I opened the first time and on the laptop, I got this same error, however XP let him program continues to work and he opened and held its positions. The Office opened and ran without error.
So my question is why this software is triggering this error when I open it up on top of my vista machine, and how can I work around this problem or solve the problem, so I can use my software.
The error indicates that microsoft will let me know when a solution is available, but that never happens.
Any light you can throw on that would be great.
Try to run the software in Compatibility Mode: http://www.vistax64.com/tutorials/75909-compatibility-mode.html to see if that helps.
What is the EXACT error message (Word for Word)? What version of Vista you are using? What is the name and version of the software (and the Web site if you have one)?
If this does not work, try a boot minimum http://support.microsoft.com/kb/929135. If the problem goes away then it's just a matter of tracking down the culprit at the origin of the problem. Follow the procedures described in the article. Once found, remove, delete, disable or uninstall. Once remember to put Vista in normal status, as described in the procedures. If the problem occurs in clean mode then just restore the system to normal and reboot - this solution will not work.
Start in safe mode with network and see if the problem is here. A result allows us to narrow down the search for the cause.
I hope this helps. Please include answers and results in your response if it does not work.
Good luck!
Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.
-
keyboard problems - some digits.letter do not work
keyboard problems - some digits.letter do not work,
Hi chrisUC,
· What happens when you try to access these numbers and letters?
· You get the error message?
· What is the brand and model of the keyboard?
· Using a laptop or desktop?
Follow the steps in the article.
Troubleshoot wired keyboards that do not or only the erroneous characters category
http://support.Microsoft.com/kb/258826
Troubleshoot the incidents of the response to the mouse or wireless keyboard
-
DVD/cd burner no longer works. Instlled SP3, no computer behaves as it is not yet connected. No reader, its firmware. No filter I know cuttin git. Not a problem of drive letter, carries the reader will not be open yet.
Hello Justuslonginus,
Thank you for your message. What is the brand of your computer? It could be that your computer manufacturer has a required update before installing SP3. You should check with them before moving to the next steps. After checking with you computer manufacturer, try to run the new hardware wizard to scan. The instructions are below:Click "Start" > click on "Control Panel" > double-click "Add Hardware".Answer that the device is already connected and allow the system to scan.If your system has not yet found your drive. Then we can remove SP3 to see if it was the culprit. Click HERE for instructions to remove the SP3.Please let us know if it did or did not help to resolve this problem.See you soonEngineer Jason Microsoft Support answers visit our Microsoft answers feedback Forum and let us know what you think.
-
My Media Player is not let him come his pass. I tired FixIt and followed all the links there and I still can't get media player to read suggestions?
original title: Windows Audio recordingHello
(1) what version of the Windows operating system is installed on your computer?
(2) did you of recent changes to the computer before the show?
(3) what is the file format of the files you are trying to play?
(4) you get an error message?
(5) you are able to hear the sound of Windows and other applications?
(6) that Microsoft Fixit ran?
You can try the following methods and check if it helps.
Method 1: No sound in Windows
http://Windows.Microsoft.com/en-us/Windows/help/no-sound-in-WindowsMethod 2: Problems running Windows Media Player
Open the troubleshooting Windows Media Player settings Troubleshooter by clicking the Start button, then Control Panel. In the search box, type Troubleshooting, and then click Troubleshooting. Click view all, and then click the Windows Media Player settings.
See this link:
http://Windows.Microsoft.com/en-us/Windows7/open-the-Windows-Media-Player-settings-Troubleshooter
Method 3: Solving problems run Windows Media Player library
http://Windows.Microsoft.com/en-us/Windows7/open-the-Windows-Media-Player-library-Troubleshooter
-
Father has not installed the latest update. Now its ipad won't let him.
My father didn't download the updated ipad. Now he's not let him? It is said that it is up to date, but it is a patch behind. There is no install when it was lit on its home screen. There are probably three weeks. Now its iPad isn't work correctlly. He said that it is up-to-date. It is not the case. He is one behind.
Try resetting the device- restart your iPhone, iPad or iPod touch - Apple Support
-
I run Firefox version 39.0 but told me that my version of Firefox is outdated even by the Mozilla site.
About Firefox said I'm updating version 39.0 + solutions for older versions do not seem to work.
I tried to download the full installer and run it, https://www.mozilla.org/firefox/all/
(he was supposed to detect my existing installation and update).
Then reopen Firefox and go to this site.
Yet this site advises again once update me my version of Firefox...
I would appreciate your help.
Keep up the good work,
Thanks in advance,Gunter Von Breslau
If you couldn't fix it by resetting the custom entries general.useragent subject: config as described in the article above, then you might also Update firefox that should address this issue as well...
-
I have a problem with the letter p
Cuando presiono p be p escribe y followed sola escribe muchas barras diagonal invertida
Google translate:
I have a problem with the letter p
When I press the p and p is written follow-up written itself that several inverted diagonal bars
Try another keyboard.
What specific model Mac? This is the Office Mac Pro forum
-
Bottom Line: I HATE Firefox 4. It gives me all sorts of weird problems not to mention the frequent freezing MAC OS x 10.6.7. I want to go back to the last #3. It has been impeccable. And I tried to present this as your comments but when I hit the button submit, again, it would take. Grrrrrrrrr
http://support.Mozilla.com/en-us/KB/installing+a+previous+version+of+Firefox
-
HP 240 G4: Drivers for HP 240 g4 - wifi problem not connect properly
Hi all
We are a group of students at a University in the Argentina. We get HP nootebooks to make a lab. But we have a big problem with the weak WIFI signal. We found a post were the problem is resolved the with the same model: HP 240 G4:
Our problem is that the URL is not avialable more to download the driver. We tried to contact HP or Paul Tikkanen support, but we do not yet have all the answers.
PLEASE HELP US!
THANK YOU VERY MUCH IN ADVANCE!
The National University of La Matanza Buenos Aires Argentina Juan
Hello:
It seems that HP has removed this driver I posted on the support site.
See if it works for you...
This package contains the Broadcom Wireless LAN drivers for the laptop models running a supported operating system. Broadcom wireless LAN drivers are required to activate the built-in Broadcom wireless LAN adapter.
Exit the: March 16, 2016
Version 7.35.344.0 Rev.A
File name: sp75249.exe
-
MY FIREWALL IS NOT TURNED ON. I CAN'T CHANGE THE SETTINGS, BECAUSE I GET A MESSAGE THAT SAYS BECAUSE OF A PROBLEM NOT IDENTIFIED, IT CANNOT BE DISPLAYED.
HOW CAN I FIX IT?
Hello
Please do NOT post in all capitals.
What do you use for security?
If you are using an Internet Security Suite, it will have its own firewall and disables the default Windows Firewall.
And you should have only one firewall to avoid problems related to the operating system.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Malware to disable your firewall and your safety programs.
Download, install, update and scan your system with the free version of Malwarebytes AntiMalware in Mode safe mode with networking:
http://www.Malwarebytes.org/products/malwarebytes_free
See you soon.
-
my hotmail account having problem not to open emails can help you pls
my hotmail account having problem not to open emails can help you pls
Hello
The Hotmail service problems. See the following link to check the status of the service.
Status of hotmail - Windows Live: https://status.live.com/detail/hotmail
Once the service has been restored, there will be a notice at this link.
Concerning
-
Original title: WINDOWS firewall
I GET A MESSAGE WHEN I TRY TO CHANGE THE WINDOWS FIREWALL SETTINGS - "DUE TO A PROBLEM NOT IDENTIFIED, WINDOWS CANNOT DISPLAY WINDOWS FIREWALL SETTINGS. HOW CAN I SOLVE THIS PROBLEM?
IN ADDITION, I USE AVG INTERNET SECURITY 2013 AND THAT THE FIREWALL IS ENABLED AND I SEEM TO BE PROTECTED.
Documentation AVG Internet Security 2013 States:
Recommendation:
Generally it is not recommended to use more than one firewall on a single computer. Computer security is not enhanced if you install several firewalls. It is more likely that some conflicts between these two applications will occur. Therefore, we recommend that you use only one firewall on your computer and disable all others, thus eliminating the risk of potential conflicts and problems related to this.
You can read the AVG documentation by clicking on this link, and see section 6.5:http://AA-download.Avg.com/filedir/doc/AVG_Internet_Security/avg_isc_uma_en_2013_06.PDF
So, if you are using AVG firewall, it's wise to just disable the XP firewall for more than a firewall running at the same time can lead to performance problems. Choose one or the other, but not both.I thought installing AVG would understand this by itself, and you know what to do (used to) but I do not want to install AVG to see.
-
When I try to turn on the Windows Firewall, I get a sign message that says "Due to a problem not identified, Windows cannot display the firewall settings."
I found another thread in Microsoft Answers relating to this problem, but who said to go into Services and see if the firewall is configured to automatically start. However, I can't find a Windows Firewall item in the Services Menu.
I have the PC Tools Spyware Doctor antivirus.
I had to do a complete recovery system... which sets just need to make sure that you back up your files.
-
From a security point of view, I don't want to not allow Adobe Flash in my democratic security but whenever I hit the sayinf box not to allow that box keeps popping up even though I tell him permit. Very frustrating.
In Internet Explorer, go to Tools / Internet Options / Security / Restricted Sites and add the Adobe site sends you this popup (or add all adobe). To block messages, even as pop-up windows.
I hope this helps.
Good luck!
Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.
Maybe you are looking for
-
Comment on the time of sunset.
When I put to bed for the alarms of the week, AOS alarms work correctly. However, I noticed that even if I had a scheduled Monday alarm AM, I don't have an alert Sunday night. Sunset alerts have to be compensated forward, not back.
-
improve the readability of the pictures taken on i-phone 6
People, I use an iPhone 6 to take pictures. My quality is 11.7 GB and my version is 9.3.2 (13F69). Can I take a photo and send it to another mac, but I have problems, showing a readable picture. I liked to retouching photo, but need help. I'm a n
-
Hard drive Compitabilty for Qosmio G20
Hi I have a Qosmio G20-139 with a drive of 80 GB H., can I use a standard 2.5 "in this laptop or what model should I use? I noticed that the connector of the standard 2.5 "is different from the one installed in the G20-139
-
I use VBAI 2011 and LV2010. I design a VI using LV and use it for my VBAI app: VBAI will transmit the data to the VI by updating the user interface of inspection. Throughout it works fine until I have add a 'linear curve fit' in the VI - and the erro
-
Unable to start cold the Windows XP computer
Original title: computer starts not cold.Cold, after that turn off for a while, the computer doen't start when turned on, have to light several times so he can start the boot process. Fan comes on, but it doesn't progress thruogh the start-up. Once i