To find a value that does not move to columns

Version of database 11g (11.2.0.3.0)
AIX OPERATING SYSTEM

I'm writing some SQL/PLSQL, who selects a value in a table that is not always in the same column. I need to find which column is on a table, then use this place of the column to find its value coresponding on another table.

Example:
CREATE TABLE TIMES (RUN_ID  NUMBER(10),TIME1 NUMBER(10), TIME2 NUMBER(10), TIME3 NUMBER(10), TIME4 NUMBER(10),TIME5 NUMBER(10));
CREATE TABLE VALS (RUN_ID  NUMBER(10),VAL1 NUMBER(10), VAL2 NUMBER(10), VAL3 NUMBER(10), VAL4 NUMBER(10),VAL5 NUMBER(10));

INSERT INTO TIMES VALUES (1000, 1,2,3,4,5);                          
INSERT INTO TIMES VALUES (1001, 2,3,4,5,6);                          
INSERT INTO TIMES VALUES (1002, 3,4,5,6,7);                          

INSERT INTO VALS VALUES (1000, 101,102,103,104,105);                          
INSERT INTO VALS VALUES (1001, 106,107,108,109,110);                          
INSERT INTO VALS VALUES (1002, 111,112,113,114,115);                          

SQL> select * from times;

    RUN_ID      TIME1      TIME2      TIME3      TIME4      TIME5
---------- ---------- ---------- ---------- ---------- ----------
      1000          1          2          3          4          5
      1001          2          3          4          5          6
      1002          3          4          5          6          7

SQL> 
select * from vals; 

    RUN_ID       VAL1       VAL2       VAL3       VAL4       VAL5
---------- ---------- ---------- ---------- ---------- ----------
      1000        101        102        103        104        105
      1001        106        107        108        109        110
      1002        111        112        113        114        115
So for a time-say 3, I want to be able to find first the rows and columns, it appears in on the TIME table and the upward gaze of the WALTZ in the same places of the column in the table VALS.

Thus, for example the time 3 above, I want to be able to return:

1000 103 RUN_ID
1001 107 RUN_ID
111 1002 RUN_ID

I got a database that stores values like that so I can't change the way the data is unfortunately inspired. Is there one clever way to do other than look at each TIME column by Union them together, then creating some dynamic sql statements to get the values of the VALS table?

This is a simplified example, but the table has 98 columns!

Any help will be greatly appreciated.

Published by: 991224 on March 1st, 2013 07:13

Hello

Welcome to the forum!

Thanks for posting the CREATE TABLE and INSERT statements; It's very useful!

If you cannot permanently normalize the data, then you can normalize it on the fly.
Here's one way:

WITH   unpivoted_times     AS
(
     SELECT     run_id
     ,     col_num
     ,     t_val     -- If wanted
     FROM     times
     UNPIVOT ( t_val
            FOR  col_num IN ( time1  AS  1
                                    , time2  AS  2
                                    , time3  AS  3
                                    , time4  AS  4
                                    , time5  AS  5
                            )
          )
     WHERE     t_val     IN (3)     -- or whatever
)
SELECT   v.run_id
,      CASE  t.col_num
            WHEN  1  THEN  val1
            WHEN  2  THEN  val2
            WHEN  3  THEN  val3
            WHEN  4  THEN  val4
            WHEN  5  THEN  val5
      END   AS v_val
FROM      unpivoted_times  t
JOIN      vals            v  ON  v.run_id  = t.run_id
;

If the same number of target may occur more than once on the same line at the time, then the above query generates multiple lines with the same run_id. For example, if we change your data a little examples:

-- Don't use this row:
-- INSERT INTO TIMES VALUES (1002, 3,4,5,6,7);
-- Use this row instead:
INSERT INTO TIMES VALUES (1002, 3,3,3,6,7);                          

Leave all other sample data, as you have it posted, then the output is:

`   RUN_ID      V_VAL
---------- ----------
      1000        103
      1001        107
      1002        111
      1002        112
      1002        113

If you have 98 (not just 5) columns that need to be compared, then you will need to list all 98 of these columns at the time in the UNPIVOT clause and all 98 of vals in the expression BOX. Sorry; I don't see any way around that. You could write dynamic SQL statements to the parts of code for you.

Tags: Database

Similar Questions

  • Create a static button that does not move when you slide on several pages.

    Is it possible to do? I have a button that directs the user to the top of the document, but it is position moves when you drag on several pages. Is it possible to create something that is entirely static which remains in the same position?

    Thank you

    It's not a way to do this in DPS. All the elements are linked to the page.

    Neil

  • Find a record that does not exist and displays a message

    When I run the following query why used, it displays the word 'FAILURE '.
    SELECT 
      CASE 
        WHEN table_name IN('DBA_OBJECTS') THEN 'PASS' 
        ELSE 'FAIL' 
      END TABLE_EXISTS 
     FROM dictionary 
    WHERE table_name = 'DBA_OBJECT'
    ;
    Ben

    Hey Benton,

    The query filter (WHERE table_name = 'DBA_OBJECT') cause zero record is returned.

    To trick you can use aggregate function that always return the single record even if the record is found or not. If no record is found, NULL is returned.

    SQL> SELECT CASE WHEN MAX(table_name) IN('DBA_OBJECTS') THEN 'PASS' ELSE 'FAIL' END TABLE_EXISTS -- OR NVL2(MAX(table_name),'PASS','FAIL') TABLE_EXISTS
      2  FROM dictionary
      3  WHERE table_name = 'DBA_OBJECT'
      4  AND ROWNUM = 1
      5  /
    
    TABLE_EXISTS
    ------------
    FAIL
    
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            
    
  • How to create a navigation bar that does not move

    I'll keep it short:

    How to create a navigation as abduzeedo.com bar? Just on the screen.

    You can use a div with CSS position: fixed; top: 0 defined.  This will allow the div to 'stick' to the top of the page, regardless of the place where the document is scrolled.

  • How to view photos that does not belong to any Album

    I would like to organize my photos according to the Album. In iPhoto, if the photo is not in any case, its automatically appears in "Untitled event".

    But in the Photos, we have no events. So I have to sort photos from Albums.

    How to find the photos that does not belong to albums?

    Define a smart album with smart rule: "Album is not everything.

    File > new > smart album

  • [SOLVED] Backup Windows 7 gives an error message 'file ignored' for a subfolder that does not exist in Documents

    I am running with "Backup and Restore" backups in Windows 7 Professional and constantly get this error in the logs:

    Backup has encountered a problem during the practical C:\Users\Tim\Documents\Blender file backup. Error: (the system cannot find the specified file. (0 x 80070002))
    "Practical Blender" is a folder I previously removed documents and backup should not be looking for it. I tried to remove the job from the scheduled backup with Windows Task Scheduler and create and execute a new backup job, but the problem goes away. It is only this specific file gives me this problem. I deleted the other folders of Documents before and since it was started without any problem of backup.

    Is it possible that I can stop backup to find this file that does not exist?

    What happens when you recreate this folder?

  • How to pin a point to move the list that does not appear in the common?

    http://www.eightforums.com/attachments/F1/F11/8991d1348615884-jump-lists-back-up-restore-Windows-8-file_explorer_jump_list.jpg

    I have file Explorer related to my taskbar. In the jump list, I can able to locate an element in the common area. But necessary file appears automatically on the point frequented it take time. I don't know how windows take to put inside of the frequent. With waiting for that appears automatically, is there a way we can pin an item that does not appear in the jump list frequent list?

    http://www.eightforums.com/attachments/F1/F11/8991d1348615884-jump-lists-back-up-restore-Windows-8-file_explorer_jump_list.jpg

    I have file Explorer related to my taskbar. In the jump list, I can able to locate an element in the common area. But necessary file appears automatically on the point frequented it take time. I don't know how windows take to put inside of the frequent. With waiting for that appears automatically, is there a way we can pin an item that does not appear in the jump list frequent list?

    The answer depends on what type of element you want to pin.  The only type of element you mentioned being a folder, you can easily do what you're wondering now and does not need to wait for a later version.

    In the 8 Windows desktop, when you drag an executable file (or shortcut) on the taskbar, a message appears that says "PIN to the taskbar.

    If you drag a document file (or a shortcut), the message will say "pine [associated application]"-in other words, "[name of the default browser] pine" for a html, "Pin to Notepad" file to a txt file, etc..

    For a folder, File Explorer is the associated application.  Therefore, if you open a file Explorer window, look for the desired folder and drag it to the taskbar, the message that appears is "PIN to the file Explorer."  Just click on it, and it will appear in the jumplist FE, above the frequent places, in a separate section called "Pinned".  You can drag things and down from there to order at your leisure.

    (The Control Panel, even if it is displayed in FE as 'File system', only let you pin on the desktop, for not not FE jumplist.)  There may be other special cases like this; I don't know, but it works usually as I've described, including for other system folders.)

    Just to be clear, I am a new user of Windows 8, far from being an expert.  I only know how it works because I heard today by trial and error.  So there may be more to what I can't help with.

  • I get a JavaScript Application error: "setTimeout" called on an object that does not implement the interface Window for Firefox.

    I get a pop up box with the message: Application JavaScript error: "setTimeout" called on an object that does not implement the interface Window for Firefox.

    But it seems to appear when I go to Amazon.com. Then he opens with this message and the OK option? But as fast as I can click OK, another box appears. After all a half dozen, she disappears - until what I move to another part of Amazon! I uninstalled - reinstalled and then - Firefox and BA. I do not understand this!

    (And of course, there is always the possibility that it is not only attacking me on Amazon... There may be a lot of other sites that also trigger, and I just haven't been there yet.)

    Hello

    Try Firefox Safe mode to see if the problem goes away. Firefox Safe mode is a troubleshooting mode that temporarily disables hardware acceleration, restores some settings and disables add-ons (extensions and themes).

    If Firefox is open, you can restart Firefox Safe mode in the Help menu:

    • In Firefox 29,0 and above, click on the menu button

      click Help

      then select restart with disabled modules.

    • In previous versions of Firefox, click on the Firefox button in the upper left of the Firefox window and click help (or click on help in the Menu bar, if you do not have a Firefox button) and click on restart with disabled modules.

    If Firefox is not running, you can start Firefox in Mode safe mode as follows:

    • On Windows: Hold down the SHIFT key when you open the desktop Firefox or shortcut in the start menu.
    • On Mac: Hold the option key during the startup of Firefox.
    • On Linux: Exit Firefox, go to your Terminal and run firefox-safe-mode
      (you may need to specify the installation path of Firefox for example/usr/lib/firefox)

    When the Firefox Safe Mode window appears, select "start mode safe."

    If the problem is not present in Firefox Safe Mode, your problem is probably caused by an extension, theme or hardware acceleration. Please follow the steps described in the section Troubleshooting extensions, themes and problems of hardware acceleration to resolve common Firefox problems to find the cause.

    To exit safe mode of Firefox, simply close Firefox and wait a few seconds before you open Firefox for normal use again.

    When find you what is causing your problems, please let us know. This might help others with the same problem.

  • iTunes does not move files to the Recycle Bin

    Today I noticed that when I delete a song in iTunes and select the option "Move to trash", the file does not move in my trash and rest in the iTunes media folder. When I right click on a song in iTunes and select "Show in finder" and delete the song here I am prompted for my password for finder make changes... I suspect that this could be the problem. iTunes cannot go beyond the 'enter password to make changes in the finder' automatically? Help, please! It's pretty frustrating

    Thanks in advance

    RosBufo

    I'm not positive, but it sounds like a permissions issue. Back up your computer then:

    Read the part about changing the permissions on the folder iTunes: https://discussions.apple.com/message/11583914#11583914

    LincDavis June 2015 post on the whole correction of the permissions on the Directory user-

    https://discussions.Apple.com/message/28436841#28436841

  • Touchpad on my HP Mini 110-1125NR is locked and the cursor does not move

    I've never locked my computer.  Everything has been implemented in the store where it was purchased about 4 years ago.  I put my computer in sleep mode yesterday afternoon and just tried to use this evening... somehow, the touchpad is inadmissible and the cursor does not move.  He remains in the middle condition of the screen.  I turned off the computer and restarted, nothing done.  Can anyone provide a solution?

    Hello

    Shut down the laptop, unplug 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.

    If the pointer is still frozen, try double clicking the top left of the button.

    Kind regards

    DP - K

  • NULL does not move with the tracking data

    I created a track in Mocha AE and copied to the Clipboard.
    Then, I created a Null value in AE and pasted the follow-up data on it.

    However, Null value does not move.
    Any ideas?

    PS I have watch it during the follow-up process, and grooving of X, I created did move/track.

    you have a composition of 54 Minutes here. you are going to restore all 54 minutes with the 54 minutes of elements trained using data from mocha in sequels? I guess that the answer is no. first thing you have to do is on the duration of the shot you want to make your composition. so only you take to mocha and follow your footage.

    so in your example, I guess you should take about 30 seconds, or maybe more? Set the workspace accordingly:

    then cut the timespan to duration:

    then you should have this:

    Ahhh MUCH better. only the length you need. now use the rail in Mocha Ae option. in case of mocha, you will again see the duration of your huge video file:

    to keep things organized you can zoom timeline in the / points so that you can see just the graven images and will not get confused by 53.5 minutes of video you don't need. Press here:

    now, you will see this - just your images carved

    track data, export and when you paste data - make sure that you are on the first image.

    Good luck!

  • The column that does not match when comparing two records

    Hi all

    We try to compare two tables and find the differences. So if two records (1 of each table) have same PK but not always matching because of some columns, then we would display this columnname. For example:

    Table 1

    PK Parent Child Property1 Property2
    1AA1P1PR1
    2BB1P2oraPR2
    3CC1P3SRP

    Table 2

    PK Parent Child Property1 Property2
    1AA1P1PR1
    2BB1P2PR2
    3CC1P3PR4

    In the above example when I compare 2 tables all matches except Property2 online n ° 3. Thus, we would like to get an output like:

    PK Column_Mismatch
    3Property2 (this must be the name of the column that does not match)

    Appreciate the help.

    Thank you

    Andy

    Hi, Andy.

    Andy1484 wrote:

    Hi all

    We try to compare two tables and find the differences. So if two records (1 of each table) have same PK but not always matching because of some columns, then we would display this columnname. For example:

    Table 1

    PK Parent Child Property1 Property2
    1 A A1 P1 PR1
    2 B B1 P2 oraPR2
    3 C C1 P3 PR3

    Table 2

    PK Parent Child Property1 Property2
    1 A A1 P1 PR1
    2 B B1 P2 PR2
    3 C C1 P3 PR4

    In the above example when I compare 2 tables all matches except Property2 online n ° 3. Thus, we would like to get an output like:

    PK Column_Mismatch
    3 Property2 (this must be the name of the column that does not match)

    Appreciate the help.

    Thank you

    Andy

    Why you don't want no matter what exit for pk = 2?  Property2 does not correspond either to pk.

    What happens if the 2 columns (or more) do not match?  The following query would produce a list delimited, such as ' parents; PROPERTY2 '.

    WITH got_mismatch AS

    (

    SELECT pk

    , CASE WHEN t1.parent <> t2.parent THEN '; PARENT' END

    || CASE WHEN t1.child <> t2.child THEN '; CHILD ' END

    || CASE WHEN t1.properry1 <> t2.property1 THEN '; PROPERTY1 ' END

    || CASE WHEN t1.properry2 <> t2.property2 THEN '; PROPERTY2 ' END

    AS the offset

    FROM table_1 t1

    JOIN table_2 t2 ON t2.pk = t1.pk

    )

    SELECT pk

    , SUBSTR (incompatibility, 3) AS column_mismatch

    OF got_mismatch

    WHERE mismatch IS NOT NULL

    ;

    If you would care to post CREATE TABLE and INSERT statements for your sample data, and then I could test this.

    The query above does not count NULL values as inadequate.  If you want that, the same basic approach will work, but you can use DECODE instead of <> to compare columns.

    What happens if a pk exist in a table, but not the other?  You want an outer join, where I used an inner join above.

  • "The value entered does not Format of the field.

    If something similar has been posted, I apologize! I tried to look for it and has not been able to find the answer.

    I have a form to determine the potential savings, if a customer makes our products to a competing product. Our sales staff filling in many areas that allow us to determine the annual cost that the customer currently committed, as well as the potential annual costs associated with our product. At the bottom of the page, using a simple calculation JS, it determines annual dollar savings by changing brands.

    I would also like to include the annual savings as a percentage of current costs, but for some reason, I cannot get the script to work. The error message that appears indicates: "the value entered does not match the format of the field [annual percentage savings]."

    Now, the two fields referenced in my script are formatted in dollars, so I don't know if this makes a difference or not. My script is below.

    var f = this.getField("Potential_Annual_Savings_in_Dollars").value;
    var y = this.getField("Cost_Per_Year_Current").value;
    F.value = Event.Value / y.value;

    If (y.value < f.value) event.value = ";

    Given the percentage is not strictly necessary, but it adds to the form, so that any help would be appreciated.

    Thank you!

    Post edited by: MelissaZoller (format)

    I would use:

    var f = this.getField("Potential_Annual_Savings_in_Dollars").value;

    var y = this.getField("Cost_Per_Year_Current").value;

    If (y<= 0)="" event.value=''>

    else {}

    Event.Value = f / y;
    If (y< f)="" event.value=''>
    }

    In this way there is no division by zero or a negative number.

  • Is there such a thing as a USB wireless, that does not need USB cable upstream that goes into the usb slot in the main computer?

    Is there such a thing as a USB wireless, that does not need USB cable upstream that goes into the usb slot in the main computer? I've looked everywhere but I can't find one. I hate the son, and I try to clear my desk of as many people as possible.

    # USB is cable only.

  • Sites of bookmark in the file that does not appear in the window

    I need to put several websites in a folder, I named "Accessories". He is not one of the four files in the drop down window. So, I have to save it in one of the four and then open that folder and move the site to the "Accessories" folder

    Is it possible to change the four sites in the window (two of them that I haven't used in years)? Then go straight to this folder?

    The seal shows what is happening.

    What I want to do is to click "bookmark this page" and be able to put it directly in a folder.

    I want to change the four folders listed in the drop-down list.

    What I do is put a bookmark in the 'Western Short Story' folder, and then open up the bookmark in the "Accessories" folder that does not appear in the box.

    It's not a huge deal, but I'm working on about 20 sites today and I would like to save a few steps.

Maybe you are looking for

  • Change fonts in Safari 9.0.2

    Safari 9.0.2 no longer has the "Appearance" option in preferences. I get some wacky my collection of type fonts, and I do not know how to restore. Since the version 9.0.2 no longer has the "Appearance" tab, I'm hard-pressed to find a way to return to

  • 8470p: Elitebook 8470p help install XP

    Hello I need help. I want to install Win XP 32 bit on my Elitebook 8470p, which came with Win8. I need to do a clean XP install on the laptop. If anyone can help me please you through the steps necessary to install XP on this laptop? I have a bootabl

  • AS Desktop M32CD: Printer-wireless computer

    I had the printer (HP Photosmart 6525) working with my new computer (AUSA M32CD) wireless recently, but traveled for 4 days and turn off the computer during this time.  When I got home, I turned on the computer back, checked the router wireless (Netg

  • Display size of Spider Solitaire

    Anyway is to decrease the size of the cards while playing?  They are big enough for people on the street to see my pieces.

  • Laptop with XP/Ubuntu Dual Boot (grub 2, not to wubi). How to safely to Windows 7 without losing the dual boot ubuntu?

    Hello I have a laptop Dell Inspiron 6400/1505 (1.73 Gz, Intel Core 2 Duo, 2 GB RAM, 750 GB (7200 RPM) HARD drive) with Windows XP and Ubuntu 12.04 LTS installed in dual boot. I installed Ubuntu in a separate partition, not not using WUBI. Since suppo