Remove the statement with a subquery

Hi Experts,
I currently have a select query with subquerys, I want to turn it into a deletion request.
select cy.lmp, cy.dt from 

(SELECT LMP, CHANGE_SD, ADD_MONTHS(DT,12) AS DT 
FROM FORECAST WHERE EVENT = 'GROWTH RATE') ny --next year,

(SELECT LMP, CHANGE_SD,  DT 
FROM FORECAST WHERE EVENT = 'GROWTH RATE') cy -- current year

where ny.change_sd = cy.change_sd and ny.dt = cy.dt and ny.lmp = cy.lmp
order by cy.lmp;
Here, I want to delete rows from the table the forecasts which are the result of the select query above.

Your help is appreciated.

Hello

Will there be matching columns in the forecast table?
If so, you can do this:

DELETE  forecast
WHERE   (column_a, column_b) IN
(SELECT  cy.lmp,   cy.dt
 FROM    ...     -- rest of query (except ORDER BY clause) goes here
);

Tags: Database

Similar Questions

  • Remove the statement with subquery with more than 1 columns

    Hi all

    I want to delete the data in the kpi_logs table for which the kpi_def_id column is less than the max (timestamp). The timestamp is the date data type. I wrote below query but its throwing an error as an SQL error: ORA-00936: lack of expression.

    DELETE FROM KPI_LOGS WHERE (Select MAX (TIMESTAMP), KPI_DEF_ID of the KPI_DEF_ID KPI_LOGS GROUP);

    Hello

    user12251389 wrote:

    I want to delete the data in the kpi_logs table for which the kpi_def_id column is less than the max (timestamp). The timestamp is the date data type. I wrote below query but its throwing an error as an SQL error: ORA-00936: lack of expression.

    DELETE FROM KPI_LOGS WHERE (Select MAX (TIMESTAMP), KPI_DEF_ID of the KPI_DEF_ID KPI_LOGS GROUP);

    Whenever you have a question, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the accurate results you want from this data, so that people who want to help you can recreate the problem and test their ideas.

    If you ask about a DML operation, such as DELETE, and INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum:

    You want to keep only the maximum timestamp for the entire table, or you want the maximum timestamp for each distinct value of kpi_def_id?

    If it is just the maximum timestamp for the whole picture, then

    DELETE FROM kpi_logs

    WHERE the timestamp<>

    SELECT MAX (timestamp)

    OF kpi_logs

    );

    If you want to keep the maximum timestamp for each individual value phew kpi_def_id, then:

    DELETE FROM kpi_logs

    WHERE (kpi_def_id, timestamp NOT IN)

    SELECT kpi_def_id

    MAX (timestamp)

    OF kpi_logs

    GROUP BY kpi_def_id

    );

    assuming that no column can be NULL.

    Moreover, the TIMESTAMP is a data type, similar to this DAY.  You'll only cause confusion by saying it is a type of data when it is really another.  In addition, TIMESTAMP is a keyword from Oracle, is not a very good column name.  Why not give your column a name more meaningful, accurate, such as create_date or entry_dt?

  • I need script to remove the line with 2 points, another script to remove next lines

    I need script to remove the line with 2 points, another script to remove next lines of two scripts needed help please

    Thanks in advance

    Concerning

    Lakshmiganth

    Scroll through each pathitem and look at the length of his pathPoints group.  If the length is equal to 2 and then use the remove() method to remove it.  For example (this is rough, off the top of my head):

    var lines = new Array();

    for (i = 0;  I have< app.activedocument.pathitems.length; ="" i++)="">

    If (app.activeDocument.pathItems [i].pathPoints.length == 2) {}

    Lines.push (App.activeDocument.pathItems [i]);

    }

    }

    for (i = 0;  I have< lines.length; ="" i++)="">

    Lines [i]. Remove();

    }

  • Remove the statement that uses a subselect in the declaration of the cursor

    Hi all

    How to write write a delete statement that uses a subselect with the declaration of the cursor?

    CURSOR excluded_dates IS          
           SELECT TO_TIMESTAMP(report_parameter_value, in_date_format_mask)
          INTO my_current_date_time
          FROM report_parameters
         WHERE report_parameters.report_parameter_id    = in_report_parameter_id
           AND report_parameters.report_parameter_group = 'DATE_TIME'
           AND report_parameters.report_parameter_name  = 'EXCLUDED_DATE';
     OPEN excluded_dates;
      
      LOOP
        
        FETCH excluded_dates INTO my_excluded_date;
        
        EXIT WHEN excluded_dates%NOTFOUND;
        
        DELETE FROM edr_rpt_tmp_inclusion_table
        WHERE TO_CHAR(date_time, 'mm/dd/yyyy') = TO_CHAR(my_excluded_date, 'mm/dd/yyyy');
        
      END LOOP;
    
      CLOSE excluded_dates;
    Thank you

    Hello

    You can turn your cursor into a subquery IN

    DELETE FROM edr_rpt_tmp_inclusion_table
    WHERE   TRUNC (date_time) IN
    (
           SELECT TRUNC (TO_TIMESTAMP(report_parameter_value, in_date_format_mask))
    --      INTO my_current_date_time   -- Remove this line
          FROM report_parameters
         WHERE report_parameters.report_parameter_id    = in_report_parameter_id
           AND report_parameters.report_parameter_group = 'DATE_TIME'
           AND report_parameters.report_parameter_name  = 'EXCLUDED_DATE'
    );
    

    I used the TRUNK instead of TO_CHAR, but it works with TO_CHAR.

    Published by: Frank Kulash, June 8, 2009 11:28
    Remove the "my_current_date_time" line, after Sean and Sanjay (below).

  • How can I remove the 'State' that wants an installation package "status.msi" I do not have?

    This laptop does not accept even in SP3. It doesn't have enough RAM for Win7.   I got rid of bad bits with chkdsk.  Status tries to install all the time & I can't find how to remove it.

    Hello
    I've got SP3 now after 2-3 attempts.  (Just 'failed to install.")
    And for the status "the component you are trying to install is on a CD or another removable disk that is not available."
     
    "Insert the diskette in the State, and then click OK.   Use Source 1. "The next window"cannot find an installation package for the product status.  Again the installation again using a valid copy of the installation package "status.msi." "
     
    The link with Microsoft wasn't working, so I checked on Google and found this annoying file is a file of HP printer so I deleted the HP printer program, which got rid of the file.  It seems, I then have to re - install the program without checking the update box, I'll try it when I have the time.
    Thanks a lot for your help.
  • Safely remove the device with VISTA is not infallible

    I have a HP Pavilion Slimline nine running Vista.

    I plug a USB key or an external hard drive and it reads very well.

    I have try the safely eject button, and the light on my memory stick stays on. With XP, it came out, and I knew that I could remove the stick. It goes the same for my external hard drive... Done, I could hear that he stop and watch out slight shift when I used the feature of MATERIAL in any SAFETY REMOVE (SRH) of XP.

    Not the case with VISTA. After completing the SRH steps, these devices always seem to be on.

    I read that Vista not turn off light after things are ejected... is - it true?
    Any suggestions?

    Are there any patches or downloadable patches?

    Hello walden1,

    Thanks for posting on the Microsoft answers Community Forum.

    The only time where SRH did not finish is when there is an application or a service that is always access the drive somehow.  I fyou're sure there is no transfer, then you can disconnect with the safety of the food.  themajin concern is when access to the data or transfer is underway.

    -J' read that Vista not turn off light after things are ejected... is - it true?
    It has been my experience that it's false.  Once ejected, using SRH or not the light turns off and the player is uninstalled.  Now, if you use memory for ready boost of course light remains lit and SRH still not eject it.  So maybe it's somehting that you'll want to check.  If your right click the drive in the Solution Explorer, then select properties the last tab should be the tab ready boost and you can switch if and how much of the training will be used for this.

    Thank you
    Jonathan

  • Remove the compatibility with older Versions of Adobe Acrobat

    I'm trying to scan hundreds of documents as PDF files using Adobe Acrobat Pro 9.5.5. I'm on Mac, the latest version of El Capitan and find that Preview 8.1, the PDF Viewer integrated for OS X, has difficulties to open a portion of my scanned documents. Interestingly, the only ones who have color in them. Black and white analysis open very well. I think it's an Apple problem, and not what I'm here for.

    Anyway, I went back to PDF it wasn't opening and Acrobat to remove compatibility with earlier versions of Acrobat. I kept compatibility with "Acrobat 4.0 and later versions. After that the file opened without problem in the preview. I noticed that the quality of the new PDF degraded slightly when I removed the compatibility. I guess that's because Acrobat must perform a new rendering of the PDF file.

    Is there a way I can create a PDF file to a JPEG file that is only compatible with versions 4.0 and later? I rather do pretty early in my workflow, and then go back and remove the compatibility and degrade image quality.

    Thank you!

    Hi Link648099,

    First thing, Acrobat 9 is not compatible with Mac El Capitan.

    The PDF created in Acrobat 9 shouldn't be compatible with version 4, please check the levers of the compatibility of the https://acrobatusers.com/tutorials/understanding-pdf-compatibility-levels PDF

    Kind regards

    Nicos

  • How to create a button in the State with two different images?

    What I mean is... I have a picture that is conveyed as a button that has not been pressed, and I also have an image that expresses the same key but this time it is pressed. Is there a way to ensure that when the button is normal I seized the image of the button upward and then make sure that when I roll on or press the Enter key, the image of the button down?

    Thank you, Ben Charter

    Hi Ben,

    Just create a Menu and with the Normal State is selected, use the fill options to fill an image in the Menu item. Select the rollover / the mouse to the bottom of the State in the States Panel, then assign an image by using the options to fill again. This is a swap of base image using normals and States of Muse down mice.

    Kind regards

    Akshay

  • Remove the line with alert button

    Hello

    I have a table which can add and delete rows dynamically. An alert must be added to the button delete what I've done.  The works warning, but when you select OK on the alert line is not deleted.

    It would be the right way to accomplish this?

    I'm not a programmer and now wondering if my edit code is wrong or there is an alternative solution.

    Thank you

    Capture.PNG

    This is the code I have for the button Delete.

    Form1. FSE_1.Pre_EX. Buttons. Remove::click - (JavaScript, both)

    CMSG var = "continues with the action underway will remove all entries in cell in this row.

    CMSG += ' \n\nDo you want to continue?

    var nRtn = app.alert (GSMC, 1, 1, 'Question Alert Box');

    if(nRtn == 4)

    {If (Table1._Item.count > 1)

    Table1._item.removeInstance (Table1._Item.count - 1);

    Console.println ("the answer is Yes");

    }

    Another yew (nRtn is 3)

    {/ / No answer}

    Console.println ("the answer is no");

    }

    on the other

    {//Unknown response

    Console.println ("the response was something other than yes/no:"+ nRtn ");

    }

    ------------------------------------------------------------------------------------------ ----------------------------------

    This is the code I have for the button Delete before adding the alert that worked.

    Form1. FSE_1.Day_1.buttons.Remove::click - (JavaScript, both)

    If (Table1._Item.count > 1)

    Table1._item.removeInstance (Table1._Item.count - 1);

    The way I understand how it works at the moment, is that you remove the last line of the table... If you want to delete the line where is the button Delete, you should be removing the instance itself with its index...

    rather than use the following line

    Table1._item.removeInstance (Table1._Item.count - 1);

    You should have something like this

    'this' being button and tell me that you have a subform to remove and add the button

    Table1._item.removeInstance (this.parent.parent.index); the first parent is the subform and the second parent is the line

    I hope this helps!

  • Add/Remove the effect with CSS

    Hello

    I'm trying to implement some sort of entry in my application validation. I expanded TextField to accept only the entry with a number of characters and corresponding to a regular expression. When the regular expression match falls, I want textfield to have an innershadow, and he does. However, the effect is not removed when I remove the CSS class where this effect is defined.

    setOnAction(new EventHandler<ActionEvent>(){
                @Override
                public void handle(ActionEvent e) {
                    if(!getText().matches(restrict.get())) {
                        getStyleClass().add("invalid");
                    }
                    else {
                        getStyleClass().remove("invalid");
                    }
    
                    for(int i=0; i<getStyleClass().toArray().length; i++) {
                        System.out.println(getStyleClass().toArray()[i]);
                    }
                }
    

    .text-field.invalid {
        -fx-border-color: indianred;
        -fx-effect: innershadow(gaussian, indianred, 5, 0.5, 2, 2)
    }
    

    The style class "invalid" appears in the table when the entry is not valid. The class is removed successfully, but not the effect. How can I fix it? Do I need to set the effect in code and no CSS?

    Have you tried this:

    .text-field.invalid {
        -fx-border-color: indianred;
        -fx-effect: innershadow(gaussian, indianred, 5, 0.5, 2, 2)
    } 
    
    .text-field {
        -fx-border-color: indianred;  // change to some other color maybe transparent or use null
        -fx-effect: null
    } 
    

    Could be he you pls tell me how to use the CODE tags.

    Post edited by: jojorabbit

  • Update of the columns with a subquery

    Hello

    I use Oracle 11.2 and need to update the columns with sub query.

    Create table tb_base (id number (5), note number (5), number YR_MO (6), total_score_season number (5), season_start_yr_mo number (6));

    Create table tb_season (season_id number (5), number start_yr_mo (6), end_yr_mo number (6));

    insert into tb_base (1, 30, 201005, 0, 0);
    insert into tb_base (1, 12, 201008, 0, 0);
    insert into tb_base (1, 43, 201105, 0, 0);
    insert into tb_base (1, 10, 201107, 0, 0);
    insert into tb_base (2, 15, 201006, 0, 0);

    insert into tb_season (1, 201005, 201009);
    insert into tb_season (2, 201104, 201108);

    I want to updat the column total_score_season and season_start_yr_mo with a single UPDATE statement as follows:
    tb_base 1, 30, 30, 201005, 201005
    42, 1, 12, 201008 201005
    201104, 201105, 1, 43, 43
    53, 1, 10, 201107 201104
    2, 15, 201006, 15 201005

    Hello

    If it is not obvious how to do an UPDATE, and then UPDATE maybe is the wrong tool for the job. Try instead MERGER:

    MERGE INTO  tb_base     dst
    USING (
              SELECT  b.id, b.score, b.yr_mo
           ,       SUM (b.score) OVER ( PARTITION BY  b.id
                                       ,          s.start_yr_mo
                                       ORDER BY          b.yr_mo
                             ) AS running_score_season
           ,       s.start_yr_mo
           FROM       tb_base     b
           JOIN       tb_season     s  ON   b.yr_mo  BETWEEN  s.start_yr_mo
                                          AND       s.end_yr_mo
          )               src
    ON    (    dst.id     = src.id
          AND  dst.yr_mo     = src.yr_mo
          )
    WHEN MATCHED THEN UPDATE
    SET   dst.total_score_season     = src.running_score_season
    ,     dst.season_start_yr_mo     = src.start_yr_mo
    ;
    

    'Total_Score_Season' means the total score at the end of the season. You're uisng as column name for a cumulative score up to certain point, perhaps in mid-season. Maybe another name, like running, or season_score_so_far scoreseason would be clearer.

    No matter what you call, a cumulative total calls the analytic function SUM. While you can use analytical functions in the corellated subqueries used in UPDATE statements, they are extremely inefficient, because they must be calculated for each line, so does want a cumulative total suggests that you want to MERGE rather than UPDATED.

  • How to create a button to run an insert and remove the statement

    Hello. I have a tabular presentation page that allows me to view the contents of a table and update the data in two columns of the table. I want to create a button on the same page and when the button is clicked the following actions occur

    1. Insert a new table all the values in the table as a table where the two editable fields are not null.
    2. remove from the table in a table all records where the editable fields are not null
    3. back to the current page... This will show me all the lines where the editable fields are always set to null.

    I tried to do this by creating a button manually and by using a sql expression to first try the Insert... It did not work. So I'm looking for a pointer to what would be the best method.
    Concerning
    Craig

    Hello

    create the button with "Defined by the dynamic action" action.

    The creation of a dynamic action on the button who has run the PL/SQL code

    Kind regards
    Richard

    -----
    blog: http://blog.warp11.nl
    Twitter: @rhjmartens
    If you answer this question, please mark the thread as closed and give points where won...

  • Remove the archivelogs with RMAN

    Hello

    I usually remove archivelogs with RMAN with command as ' ARCHIVELOG DELETE ALL COMPLETED BEFORE ' SYSDATE - 1' if I have to erase the archivelogs to free the space of FRA.»»

    My question is if I delete the archivelogs will it deletes the records in the catalog also (I think) so backed up on tape. In this case the catalogue is not information for these records even if they are on cassettes, correct?

    So in the case of collection how can I restore them?


    Thank you

    Published by: 822424 on May 15, 2011 19:28

    The catalogue contains information about the backups.

    Before you remove the archivelogs, I assume that you have done a BACKUP ARCHIVELOG (or with the database as a BACKUP database PLUS ARCHIVELOG DATA). Therefore, backups are in the BackupSets that are in the catalog.

    Hemant K Collette

  • include the component in the State with AS3

    Hi I have a tab navigator that I instantiated in my AS3 code.  I want to make this browser tab display only in some countries, but not all. How can I do this?  Obviously with mxml I can add a property 'includeIn' and assign which has it should be visible, but how would I do this in ActionScript?   Thank you, fuyuko

    The States are a concept MXML, not a concept of ACEs. In AS, you would use what logic allows you to change your status, and then do the things you want to happen next.

    override public function set currentState(value:String):void

    {

    super.currentState = value;

    do things with a bunch of instructions conditional mess

    }

    The above doesn't look natural.

    If you are interesting in creating features like State in AS native, you can look in the Model of Memento.

  • Satellite 5205-S505 - how to remove the battery with the damaged battery latch?

    I try to set aside my laptop (satellite 5205-s505) today. But I found that the release latch was damaged somehow. What can I do?

    My seriously damaged lcd. I have method to close the LCD to save energy (just use external moniter)?

    This battery is a very good question. I think you're the first person who asked it.
    If you cannot remove the only way is, I think, to disassemble the entire laptop and somehow free battery.

    When you use the external monitor, you have to use the FN + F5 key combination and switch to an external monitor only. Portable computer's LCD will be OFF.
    You can also check the Advanced display settings. Usually, you can also find settings to define where should be the office.
    Check it out!

Maybe you are looking for

  • Split screen on the iPhone 6 sec more

    Is it possible to get more split screen on an iPhone 6s?

  • 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

  • file to load different bitx

    I intend to have two screws of FPGA.  They are identical in terms of controls and indicators located on their facades, but the logic is different.  I want to compile in two separate files bitx and host VI will select the correct bitx runtime file.  I

  • Windows XP Professional does not start in any mode

    I have a Dell Latitude D610 & I got it in 2005. Its operation under Windows XP service pack 3 & I do not have all disks is it came with. I recently received a security update that I got about 15 files corrupt on the laptop, when I went to check what

  • No AHCI in the BIOS pavilion g6 option

    I was wondering if AHCI was enabled by default, because there is no option to enable/disable in the BIOS. My laptop is a hp pavilion 1d46x with BIOS F.46 g6. Thank you Oliver