Other than NVL easier way to get the records?

I have data like below. Trying to get the unique lines for toy and the child. i.e.
I just want to see the lines with fireld_name = toy for a unique event and field_name = kid for the same event that has multiple lines? I know WHAT NVL is a way to do it, but any other method?
client   eventid   fieldname
123       2345     toy

123       2356     toy
123       2356     kid

123       2462     toy

123       2589     toy
123       2589     kid

The result i want to see
123       2345     toy
123       2356     kid
123       2589     kid

user11961230 wrote:
I have data like below. Trying to get the unique lines for toy and the child. i.e.
I just want to see the lines with fireld_name = toy for a unique event and field_name = kid for the same event that has multiple lines?

What happens if multiple all lines have fieldname = 'toy', or other values outside of the child?

I know WHAT NVL is a way to do it, but any other method?

Assuming that 'toy' and 'kid' are the only possible values for fieldname, you can do something like this:

SELECT    client
,       eventid
,       MIN (fieldname)     AS min_fieldname
FROM       table_x
GROUP BY  client
,            eventid
;

However, it is not really solid programming. It relies on there are only 2 values, and 'kid' just happens to come before 'toy' by alphabetical order. A better solution would allow all values and is not in alphabetical order, like this:

WITH     got_r_num     AS
(
     SELECT  client
     ,     eventid
     ,     fieldname
     ,     ROW_NUMBER () OVER ( PARTITION BY  client
                               ,                    eventid
                         ORDER BY        CASE
                                             WHEN  fieldname = 'kid'
                                               THEN 1
                                             WHEN  fieldname = 'toy'
                                               THEN 2
                                        ELSE 3
                                         END
                        )     AS r_num
     FROM    table_x
)
SELECT     client
,     eventid
,     fieldname
FROM     got_r_num
WHERE     r_num     = 1
;

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

Published by: Frank Kulash, October 25, 2012 11:20
Added ROW_NUMBER solution

Tags: Database

Similar Questions

  • Y at - it an easy way to get the sql code that is sent in the query UPDATE

    I have a request to UPDATE abbreviated for readability. Is there an easy way to get the sql code that is sent? I use get this info for sql select in the display of debugging in cfeclipse but not for the UPDATE.

    < cfquery debug = "" name = "q" datasource = "#datasource #" > "



    UPDATE [BookingSystem]. [dbo]. [tbTrades]
    SET
    [Status] = #MATCHED_STATUS #.
    WHERE

    clientID = < cfqueryparam value = "" #arguments.clientID # "cfsqltype ="cf_sql_integer"> AND"

    < / cfquery >

    It might pay to read the docs for - http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_p-q_17.html#1102316 - focusing on the RESULT parameter.

    Read also about debugging in CF: http://livedocs.adobe.com/coldfusion/8/htmldocs/Debug_01.html

    --

    Adam

  • is there an easy way to get the number of months in a year in a date range?

    Hi, experts, I am a newbie.

    are there any easy ways to get the number of months in a year in a date range?

    I would like to write a user-defined function.

    the input parameters are startdate, enddate, year

    the output is a number, not a month.

    for example, case 1

    StartDate = 01032009 (DDMMYYYY)
    end date = 28022010 (DDMMYYYY)
    If the year 2009, the output is 10
    If the year = 2010, the output is 2

    case 2:

    StartDate = 10032009 (DDMMYYYY)
    end date = 15032010 (DDMMYYYY)
    If the year 2009, the output is 10
    If the year = 2010, the output is 3

    Thank you very much!

    Hello

    You can (also) try this:

    SQL> with s as (
      2  ------------ Sample data -------------
      3  select to_date('01032009','ddmmyyyy') startdt, to_date('28022010','ddmmyyyy') enddt, 2009 yr from dual
      4  union all
      5  select to_date('01032009','ddmmyyyy') startdt, to_date('28022010','ddmmyyyy') enddt, 2010 yr from dual
      6  union all
      7  select to_date('10032009','ddmmyyyy') startdt, to_date('15032010','ddmmyyyy') enddt, 2009 yr from dual
      8  union all
      9  select to_date('10032009','ddmmyyyy') startdt, to_date('15032010','ddmmyyyy') enddt, 2010 yr from dual
     10  ------------ Sample data -------------
     11  )
     12  select startdt, enddt, yr,
     13  months_between(
     14          least(trunc(to_date(yr+1,'yyyy'),'year') , add_months(trunc(enddt,'month'),1))
     15          , greatest(trunc(to_date(yr,'yyyy'),'year') , trunc(startdt,'month'))
     16  ) nbmonths
     17  from s;
    
    STARTDT    ENDDT              YR   NBMONTHS
    ---------- ---------- ---------- ----------
    01/03/2009 28/02/2010       2009         10
    01/03/2009 28/02/2010       2010          2
    10/03/2009 15/03/2010       2009         10
    10/03/2009 15/03/2010       2010          3
    

    It's pretty simple. (no connection with, without functions SQL only integrated multicast, etc...)

  • easy way to get the size of a filling?

    I have a program that uses a movieClip and draw a shape on it with beginFill, moveTo, lineTo, of of curveTo and endFill. Then, the user can resize and reform this form by dragging and pulling it off.

    Is there an easy way to get the surface of the shape as the number of pixels that have been filled? Or I have to calculate what it based on points.

    TIA

    Welcome to the forums. Here's a thread fairly new all about this topic.

    http://www.Adobe.com/cfusion/webforums/Forum/MessageView.cfm?forumid=15&CATID=288&ThreadId = 1172369 & highlight_key = y & keyword1 = calculate % 20area

    Check that out and post if you have any questions.

  • An easy way to get the IP address of a VMware Player running?

    Hey guys, need some help to get the IP address of a VMware Player running in windows & linux. An easy way? I search on google. I saw someone said how to limit the selection of the IP address, but this isn't what I want. I want to get the IP address of a VMware Player running in windows & linux. Thank you.

    Hi Badboy,

    Welcome to the forums.

    VMware Player has no IP address, but the guest inside the VM systems have not one.

    If your virtual machines based on the internal DHCP server of the player, for example if they are bridge now or NAT network, then on Windows, you should find information useful in the %ALLUSERSPROFILE%\Application Data\VMware\vmnetdhcp.leases. There is such a file on Linux.

    Good luck.

    Concerning

    Franck

  • Is there an easy way to get the previous record in the Apex?

    I'm new to APEX/Oracle, but have a lot of expierence as a mainframe programmer and some experience with SQL.

    I have been instructed by my boss to create a set of pages in an application like this.

    Page 1: Select an employee name and go to Page 2.

    Page 2: View employee biography information.
    Add a 'Next employee' button and a button "Previous employee" who picks the previous employees respectively biography info.

    Essentially, he wants a query with information biography of each employee with an employee selected on page 1, used as pointer to start.

    I built successfully "select the name of an employee on page 1" and "show its info on page 2" with a query that returns a single record.

    What I can not know is how to get a next and previous button for the next or previous record in a record multi query, using the initially selected employee as intial pointer.

    Is their an easy way to build this using functionailty of integrated APEX, or will it require programming to reach this requirement?

    Just realized that I didn't fully answer your question. According to the number of employees, you can create a collection to contain all the information and who travels with buttons. Or you could include a calculation to transmit the current employee, previous and next to your second page using the standard apex_application.gf01... GFN see the creation process to get the id of current line
    Keep smiling,
    Bob R

  • Y at - it an easy way to get the SVG data page d = "" an object without exporting to SVG? "

    I need a way to quickly get the data from the path for an SVG. In GIMP, they have a menu option "edit > to path" that returns the data to trace for the chosen path. Super convenient.

    Right now I am:

    1. Design of my work (icons)
    2. Make a compound path of the work
    3. Economy in SVG
    4. Open source SVG in text editor
    5. Copy the contents of d = «...» »

    Any thoughts on a quick way to get this data from illustrator?

    Instead of save on the svg have you tried just choose your icon, copy (Ctrl + C) and then go to your text editor and paste it (Ctrl + V), this should then give you the same result as if you were out saving... ?

  • I try to install vista on my laptop but a letter of the key is not visible, all the other parts are very well including the serial code, is there another way to get the key of the other information?

    Taché product key

    Hello

    I try to install vista on my laptop but a letter of the key is not visible, all the other parts are very well including the serial code, is there another way to get the key of the other information? The laptop currently has non-OS I've tried to reinstall.

    Thank you

    Scott

    Product keys are bit-agnostic - they don't care if it's 32-bit or 64-bit.

    However, cannot legally use the recovery disk from one computer to a different constructor machine - as other licenses are not properly paid..

    There is nothing nonetheless to try all possible variations on the absence of character (there are only 25, after all the )

    Other than that, your best option is to contact the manufacturer and order a set of recovery disc for the machine. I do no download available for Vista with SP2 - but you can download Vista with SP1 and create the disc.

    http://www.heidoc.NET/Joomla/technology-science/Microsoft/57-Windows-Vista-direct-download-links

  • IIOMetadataNode is there an easy way to get all the items?

    Y at - it an easy way to get all elements with no recursion to a depth of level in the XML getAsTree IIOMetadataNode ("formatname") document and make the images of type jpeg with EXIF metadata (when its present on the image) who return to the IIOMetadataNode?

    You can call getChildNodes() on the node returned by getAsTree(). The returned NodeList will contain children with a depth of level.

    The EXIF data will be be summarised into a byte array [] under a sequence of 'unknown' marker with a value of 225 marker.

    /**Returns the EXIF information from the given metadata if present.  The
     * metadata is assumed to be in 
    javax_imageio_jpeg_image_1.0
    * format. If the EXIF information were not present, then null is recuperer.* / public static ubyte [] getEXIF (IIOMetadata meta) {//javax_imageio_jpeg_image_1.0 //-->markerSequence //--->unknown (attribute: 'MarkerTag' val: 225 (for exif)) root IIOMetadataNode = (IIOMetadataNode) meta.getAsTree ('javax_imageio_jpeg_image_1.0');} IIOMetadataNode markerSeq = root.getElementsByTagName("markerSequence").item (0) (IIOMetadataNode); Notorious NodeList = markerSeq.getElementsByTagName ("unknown"); for (int i = 0; i)< unkowns.getlength();="" i++)="" {="" iiometadatanode="" marker="(IIOMetadataNode)" unkowns.item(i);="" if("225".equals(marker.getattribute("markertag")))="" {="" return="" (byte[])="" marker.getuserobject();="" }="" }="" return="" null;="">

    You must use a TIFFImageReader to analyze the table of byte [] being the TIFF metadata EXIF metadata.

  • Template file - y at - it an easy way to update the files related to a model, and download them (put) at the same time?

    First of all, I am a user of Adobe software for 20 years now.  I love the adobe range. I want to just clarify.

    Question... Template Files - y at - it an easy way to update the files related to a model, and download them (put) at the same time?

    Its been bothering me since I started using Dreamwever 10 years now, when you use template files to create small, who later turn wholesale websites. Whenever I update a template file I have to find each file in the files Panel, then download them. When I navigate through a lot of directories to find it can get a lot of time and boring.  Whey cant be just a button that does it? See the attached file.

    Is there a way to do this?  Any help would be appreciated.

    Thank you very much

    Andy

    Dreamweaver-Updated-Template-File.jpg

    The sync tool should do what you want (second "circular arrows" icon in the files window).

    Who checks your files against the files of the current server and download all that is changed. By default, is also download any file from the server which is more recent than your local files at the same time, but you can set it to 'Put the latest files remotely' rather than 'get and put newer files' and you should be good to go.

  • I'm doing a script that takes a list of e-mail from a text file and then allow me to select a save as a string. I found some ways to get the path of the file, but I'm in check by pulling the list

    I found some ways to get the path of the file, but I am defeated by pulling the list from that. the function of the path get gives me the path as "Macintosh Users:: Documents: extractedb.txt (myUsername).

    What I can't understand is how to get a dialog box to display a list that represents the content in the text file, I need to change the contents of the text file, I need the box to show me what I chose and I want to save my selection as a single string.
    e '.

    example of extractedb.txt information:

    [email protected]

    [email protected]

    [email protected]

    * has a random number of emails as well *.

    I want this is to pull those emails from the text file and turn them into a list so I can get to be a selection in my dialog box.

    Any help would be great = D

    Assuming you have a text file with your example e-mail addresses, the following AppleScript will read this file in a list (mf_List) and then use this list as input to choose among the list. Because multiple selection is allowed (control button), the output is sent to a list (sel_addr). We check if the Cancel button was pressed by testing for false and if this condition is met, we the script error.  Based on a single or multiple list item content of the list, display accordingly.

    game of mf to ((path to the folder as text) & "mail_list.txt")

    the value mf_List to {}

    the value sel_addr to {}

    the value mf_List to paragraphs of (read file mf)

    the value sel_addr to (choose from the list mf_List with title ¬

    ('Mail list' with multiple selections allowed without empty selection allowed)

    If sel_addr is equal to false then

    Error number-128

    return

    end if

    If length of sel_addr is equal to 1 then

    sel_addr display dialog box as text

    on the other

    the value Point to the text of TID to AppleScript delimiters

    the value Point text in AppleScript return delimiters

    display the dialog box elements of sel_addr in the text

    the value Text of point AppleScript delimiters to TID

    end if

    return

  • Is the another way to get the download from the support section

    Is there another way to get the download from the support section?

    Because the download speed is very slow. For example, in the new version of the value-added packaging and its 116 MB big need. A normal download time would be approximately 5-10 minutes. But when I download from Toshiba I need 2 to 6 hours. Not good for a company that manufactures laptops and high-performance computers.

    And the worst thing is that the connection is reset after a few hours... so I'll never get the update.

    Does anyone know help?

    Gruss
    Thomas

    Unfortunately, he has no other way to get the Toshiba drivers from the European pilot of Toshiba page.
    You are right at this moment that the file transfer is too long.
    I get about 10-19KO/s. That s is really very slow.
    Maybe the server is overloaded who knows I hope this will be resolved in the next time.

    Best regards

  • I converted my mp3 format.now music library, I want to delete all songs.what i, m mast mp3 this removes one time.there are 3500 songs.is it an easier way to remove the songs without losing my original library?

    change my mp3 music does, nt come out as I thought and I so do CD fashion old way and burn.when I have made a set of mp3 music library, they were all dated 06/01/16.

    now I want to know if there is an easier way to get rid of all the mp3 songs to the format of my library.i been ve music delete songs one by one. If there is a way to chat online would be helpful.some times that I don, t understand what you mean by changing the files and .i m worried that i, m going to lose all my music again.

    Yes, open itunes and right-click on the menu where the artist, Album, etc., and then scroll down the menu until you find 'Type' remember to widen the column, and then select the name until all MP3 files are grouped, then select all and delete them.

    This is the menu that I speak to you, do a right click on it and Type search

    f

  • Easy way to locate the function used on the diagram by name?

    Is there an easy way to locate the functions used in the diagram under the name of the generic function?

    I have user appears somewhat to the user on my diagram functions to help me debug a difficult sequence of agross events live multiple now that it works, I want to go back and disable most of these postings. Most of them went up to now within the layers a little structure and is not easy to find.

    So is there an easy way to get a list of where these functions are used so that I can quickly go and edit them?

    I find the function is with the display hierarchy that does just what I need.

    Thank you.

  • Is there an easy way to create "the mouse on the text, to display the image" without coding it? I want an image to appear only when you move to a line of text. I found the code for it but I want to find an easier way. Thank you!

    Is there an easy way to create "the mouse on the text, to display the image" without coding it? I want an image to appear only when you move to a line of text. I found the code for it but I want to find an easier way. I'm creating a home page with a list of text links. I want to design as well as in the overview of one of the text links, a corresponding image is displayed to the right of the page. I also need a default image to rest all the time unless one of the other links text is hovered over. Thank you!

    Try to use a Widget for Composition in the Adobe Muse Widgets Panel.

    I would like to start with a blank publication.

    Place your text in the button area.

    Place your image in the display area.

Maybe you are looking for