Add the value of column based on a different line with the same id

Hello world

I have a query that displays the first three columns of the table below. I would like to add a column to this output, most indicating (for each row) if there is an electronic product in the same order. For example, the command 1 in the table below contains 1 unit of furniture and 1 unit of electronics. In my outings, I would add a flag 'Y' for the two rows 1 and 3. Also, I would add a "N" indicator to any order which does contain all the electronics.

Any ideas on how to achieve this? Any idea or suggestion is appreciated!

order_id product_cat quantity with_electronics
1furniture1THERE
2grocery1N
1Electronics1THERE

Thank you

Zsolt

Hi, Zsolt,

You can also use analytical functions.  For example:

SELECT order_id, product_cat, quantity

MAX (CASE

WHEN product_cat = 'electronics '.

THEN 'Y '.

ANOTHER "N".

END

) OVER (PARTITION BY order_id) AS with_electronics

Orders

;

Of course, I can't test it without a table.

Tags: Database

Similar Questions

  • How can I add the same properties to the __names of a series of files

    I would like to add a few properties on the front of several files. instaead clicking Rename and add them one by one, how can I add the same properties in the names of a series of files

    Hello Ronke2009,

    Welcome to the Microsoft Answers Community!

    Using the function rename in Windows results in action that you said earlier, with all records even renamed with a number appended to the end. You can get the service you are looking for with a third party tool. A good search Bing.com for these would be something like Bulk Rename Utility or editor to rename block.

    Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    Hope that helps, I look forward to hearing from you.

    Steven
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think

  • When you add the same audio clip of chronology not added?

    When I add a clip to the timeline of the first audio is also added as usual. When I add the same clip again, that it does not come with the linked audio file. When I hover over the blue icons in the project window, it is said "audio video used 2 times 'and' related used 1 time" I want audio to be also with the clip on the second clip. Why does this happen?

    FAQ: Why no audio or video will not at the track where I let down?

  • Add the same page to several PDF at a time?

    I have 50 booklets created, and now I have to add a page for booklets. Instead of open each pdf document individually, is there a way to add the same page of pdf at the end of each book at the same time? I'm going to do this as many times that the content of the booklets are constant, and the last page is sometimes added as a page "to measure". So, if this is possible, it would be same a me lot of time. Thank you very much.

    Possible with the Action Wizard and the Javascript.

  • How to add the same name of datagrid records, while I'm by selecting one of the check and click Add end to end

    Hi friends,

    I do flex mxml 4 web application with as3, I am struck upward in the next concept, shar your suggession thereon.

    I use datagrid with 3 columns NUMBER, NAME, AMOUNT. an and a box Add button and a delete button.

    I have two records in the same name in the grid, when I click on a record in the grid and click ADD means of button this year, both AMOUNT WILL ADD records that record with the same name and give this value in a text box.

    How to do this?

    useful suggesssion or sample modal

    Thanks in advance,

    B.Venkatesan.

    Hello

    var totalsum:int = 0;

    var index: int = db.selectedindex;

    var selname:string = bd.dataprovide.getItemAt (index) .name;

    var totallen: int = (db.dataprovider) .length;

    for (var i: int = 0; i<>

    {

    var checkduplicate:string is bd.dataprovide.getItemAt (i) .name;.

    if(checkduplicate==selname)

    {

    totalSum += bd.dataprovide.getItemAt (i). AMOUNT;

    }

    }

    textfield_id. Text = totalSum

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

    Gallot Hiroji | [email protected] | www.isacglobal.com

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

  • Firefox for Android does not implement HW keyboard shortcuts, please add the same as the desktop version!

    Hello
    I use a bluetooth keyboard and noticed that the classic keyboard shortcuts do not work with Firefox for Android. This is a major gap, with chrome, you can use the same shortcuts on the desktop version, it would be nice to have a comparable feature on Firefox for Android too.

    Hardware keyboards are a useful supplement to the tablets and the last iterations of keyboard 'sexy' as one that is available for the Google Nexus 9 are practical and folio desiderable.
    Please add this improvement soon!

    Thank you!

    Hello, this is a mainly managed by the community support forum is probably not the right place for the characteristics of the request (we are unable to implement all the features & devs read here).
    Please use https://input.mozilla.org/feedback for either your reactions or if you think that it is a missing feature in the browser file a bug at bugzilla.mozilla.org.

  • How can I add the same metadata for many files

    I don't voice more work and need to add metadata to hundreds and hundreds of audio files. Some of the data is the same for ALL files.  Is there a way to fill any meta data?  They have all the same artist, same genre, date of registration, composer, technician and copyright info.

    Twice a week:

    How can I request the same information in the fields of specific metadata across multiple files, i.e. date of reference, artist, genre, composer, technician

    We will add your notes to the feature request.

  • Add the same header and footer to all of my reports

    Hello

    I wonder if someone could help me please.

    I have to add the header and footer even at 52 reports and I wonder if there is a way to do so I don't have to repeat the same things each time
    I use reports 10g

    may thanks in advance
    Ana

    Perhaps Chapter 16 "customization of reports with XML" in "Report Services of Oracle® Application Server, publishing reports on the Web, 10 g Release 2 (10.1.2), B14048-02"can help you."
    Walter

  • Determination of the value of column based on previous records

    Hello

    I have this table. Please just exclude the Prev_Equal column for my original table.
    +---------+--------+---------+---------+------------+
    | info_id | fruit  | Qty In  | Qty Out | Prev_Equal |
    +---------+--------+---------+---------+------------+
    |       1 | apple  |      10 |       7 |         No |
    |       2 | apple  |      10 |      10 |         No |
    |       3 | apple  |      10 |       8 |        Yes |
    |       4 | orange |      20 |      18 |         No |
    |       5 | orange |      20 |      20 |         No |
    |       6 | orange |      20 |      17 |        Yes |
    |       7 | orange |      20 |      20 |        Yes |
    |       8 | orange |      20 |       1 |        Yes |
    |       9 | grape  |      15 |      15 |         No |
    |      10 | grape  |      15 |      15 |        Yes |
    +---------+--------+---------+---------+------------+
    For the table of Prev_Equal, it is marked as being:
    No: if it's the first item or there is no history that has quantity = QTY OUT
    Otherwise Yes

    How do I do this in Oracle SQL?

    Thanks in advance

    Hello

    Claude2005 wrote:
    ... For the table of Prev_Equal, it is marked as being:
    No: if it's the first item

    I assume you mean the first element in order of info_id for a given value of fruits.

    or there is no history that has quantity = QTY OUT
    Otherwise Yes

    How do I do this in Oracle SQL?

    LAG can only watch a specific previous line; This is why the above fails on the line where info_id = 7. We need a function that can examine all the previous lines, like this:

    SELECT       t.*
    ,       NVL ( MAX ( CASE
                         WHEN  qty_in = qty_out
                           THEN  'Yes'
                         END
                  ) OVER ( PARTITION BY  fruit
                               ORDER BY        info_id
                               ROWS BETWEEN  UNBOUNDED PRECEDING
                           AND        1          PRECEDING
                           )
               , 'No'
               )          AS prev_equal
    FROM       t
    ORDER BY  info_id
    ;
    
  • Change the value of column select and insert different

    Hi all

    I've written a procedure where I am selecting values in other tables and inserting into a new table. The code is below
     
    If you see line 54 in the code, you will find the combined_bu_code is comes from a procedure and the value of BU is stored in prod. Table SEM_BACKLOG_LOG. I need to check, if the combined_bu_code came as PWR then insert as table BACKLOG_OTD_NEW POWER not as PWR.

    You are looking for assistance on this. Thanks in advance

    Concerning

    Published by: User_Apex on June 23, 2011 03:03

    Published by: User_Apex on June 23, 2011 03:53
    DECODE(SMTC_OTD_CHART.get_combined_bu_code(a.BU), 'PWR', 'POWER', SMTC_OTD_CHART.get_combined_bu_code(a.BU)) COMBINED_BU_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...

  • Add the same text to each hyperlink in Indesign

    Hello.

    I have a simple JavaScript search and replace text in hyperlinks. I was wondering if this can be rewritten to simply add additional text to each hyperlink in the Indesign document.

    for example "1234" will add 1234 at the end of each hyperlink. Google.com will become google.com1234

    Thank you very much!

    main();

    main() {} function

    var d = app.dialogs.add ({name: "Replace the URL of the hyperlink values"});

    col1 var = d.dialogColumns.add ();

    col2 var = d.dialogColumns.add ();

    col1.staticTexts.Add ({staticLabel: "find (GREP)": ""});

    col1.staticTexts.Add({staticLabel:"Replace:"});)

    find var = col2.textEditboxes.add({minWidth:100});)

    change of var = col2.textEditboxes.add({minWidth:100});)

    var result = d.show ();

    {if(!result)}

    d.Destroy ();

    return;

    }

    var grepForFind = RegExp (find.editContents, "g");

    var grepForReplace = change.editContents;

    d.Destroy ();

    var = app.documents dests [0].hyperlinkURLDestinations.everyItem () .getElements ();

    for (var i = 0; i < dests.length; i ++) {}

    DestS [i] .destinationURL = dests [i].destinationURL.replace (grepForFind, grepForReplace);

    }

    }

    Hello

    Try this...

    hlinks = app.documents[0].hyperlinks.everyItem().getElements();
    for (i = hlinks.length-1; i >= 0; i--) {
        if (hlinks[i].destination instanceof HyperlinkURLDestination){
            hlinks[i].destination.destinationURL+= '1234';
        }
    }
    

    Concerning

  • Add the same touch to three cans but only one gets the button

    Hi all

    I have these containers three pennies for my app and a button that I would add to all three of them.

    So I created the button

    totalParallal = new LabelButton();
                totalParallal.addEventListener(MouseEvent.CLICK, calculateParallal);  
    
                RightSub.addChild(totalParallal);
    

    added to a subcontainer, but when I tried to add another container (MidSub)

    MidSub.addChild(totalParallal)
    

    the button appears in my container MidSub, not the RightSub. Can someone explain to me why this is? All this is done in the function InitializeUI.

    Hey jzou,

    in AS3, all child objects can have only a single object parent. which means that the last place you add an object as a child, the new parent is the object that calls the addChild() method. important if the number of objects summon the addChild() on a single instance method, the last object that called the method will be the child object to himself.

    wats that past in your code is the MidSub container is the last caller of the of the object that you are adding, and consequently addChild() method, the final parent. you will need to create new instances of object to add it in several places. hope that things cleared up. Good luck!

  • You can automatically add the same CSS markup to each HTML export?

    I created prototypes of web page, not true web pages that serve as a clickable Visual AIDS for our design discussions.

    I wish that all my html pages of prototope to export from Fireworks CS4 without on top and left margins.  Is it possible to make it always insert a link to a style sheet or insert this style:

    < style type = "text/css" >
    <!--
    body {margin-top: 0; margin-right: 0; margin-bottom: 0; margin-left: 0;}
    padding: 0; }
    ->
    < / style >

    in each html page, it exports?

    Yes, oddly.

    This was irritating the bejeezers out of me, so I got confused in the bowels of the application files and found the docs used by Firworks to genetrate the HTML code. they can be found here:

    C:\Program Files\Adobe\Adobe Fireworks CS4\Configuration\HTML Code\

    I default to export HTML Dreamweaver thingy, so I opened the Dreamweaver folder and found a file named:

    SLICES. XTT

    First thing, make a copy of such and name it old_SLICES. XTT or whatever, in case you inadvertanlty something to spoil...

    Then open the original in Notepad and look for this string:

    Close the body tag.

    Just below this line, insert these three lines:

    WRITE_HTML(" ");

    Save and export. Voila!

    HTH

    -Ted

    Here this is a little closer:

    ("If (i > 0) WRITE_HTML (" ");") ;
    Hey!  the order here is very important.  We must put the call to MM_preloadImages() first
    because the javascript in FWLoadInit might return or cause any javascript syntax errors
    the following! (ajf - 27/03/2002)
    WRITE_HTML (FWLoadInit);
    WRITE_HTML("\"");
    }
    WRITE_HTML(">\n");    Close the body tag.
       
    WRITE_HTML(" ");

    }

    function WriteStyleSheets (curSlices, indent, topLevel) {}
    var curCol;
    var curRow;
    var prevTop = 0;
    var prevLeft = 0;

  • Multiple values per column in the stacked bar chart

    I want to use a bar chart stacked in a dashboard of the process, but I am wondering how I can add multiple values per column, because through the available methods, you can only add one value per column. I add some values to hardcode and I get the chart but, for example, I want to add series anocher in the table named 'Closed' and values for this in each column (January, February, etc.)

    Data source for filling
    result as a Fuego.Chart.DefaultXYDataSource
    result = Fuego.Chart.DefaultXYDataSource ("Opened");

    addValue result
    using
    value = 5,
    columnHeader = "January".

    addValue result
    using
    value = 10,
    columnHeader = "February".

    addValue result
    using
    value = 15,
    columnHeader = "March".

    addValue result
    using
    value = 7,
    columnHeader = "April".


    I enjoyed your collaboration if you have worked with graphics stacked bar.

    Hello

    You were very close.

    Try to use the Fuego.Chart.XYZDataSourceImpl object. This will give you the third dimension that your stacked bar chart needs and these attributes in the addValue method:

  • value
  • rowHeader (maybe that's where you set your month name)
  • columnHeader (maybe it's where set it to 'Open' or 'Closed' in your example)

    Dan

  • Any solution to add the checkbox [] without

    Hello

    I want to add the number of box (dynamically added) with various Info next to it. I can not add it as I want with all the info. But I'm not able to find a way to find which box was clicked.

    In an optimization of resources, I add a gridFieldManager who has the box [i] and 3 labels. I add setChangeListener each [i] checkbox, when a checkbox is clicked, I only am not able to know what index of chexkbox was clicked. in fieldChanged(), I have given SOP "field =" + field & he sows "field = [Yes]". ""

    No idea how to find out what index checkbox was clicked of [a] checkboxes? I took a look at

    How - to create a ListField with checkboxes

    but in what I have to passed the single string as an element. And in my case I have to add 3 labels with the specified size, which gives each column proepr size and layout.

    Any help, guidance is much appreciated.

    Thank you

    Re: the use of cookies:

    When you create your checkbox, you can issue checkbox.setCookie (anyObject). I guess you also add the same FieldChangeListener to all of these boxes.  Different boxes should get different, although cookies safe.

    In your fieldChanged (field field, int context), you can retrieve the cookie by using field.getCookie (). Then you can also mount the CheckboxField field and retrieve his verified status. If plan you properly, your cookie and this whole status should be sufficient for you to move forward.

Maybe you are looking for