Select all, when the value of the field is not distinct

Hello.

Suppose I have a table with data like this SAMPLE:

ID | Number |      Date | Data1 | Data2
________________________________________________
1. 0001 | 2001.01.01 | Data1-1 | 2-1 data
2. 0001 | 2011.01.01. Data1-2 | 2-2 data
3. 0002 | 2010.01.01 | Data1-3 | Data 2-3
4. 0003 | 2008.01.01 | Data1-4 | Data 2-4
5. 0003 | 2009.01.01 | Data1-5 | Data 2-5
6. 0004 | 2000.01.01 | Data1-6 | Computer 2-6
7. 0003 | 1999.01.01 | Data1-7 | Data 2-7

What I need is to get all the data lines that don't have NO distinct numbers. It is:


ID | Number |      Date | Data1 | Data2
________________________________________________
1. 0001 | 2001.01.01 | Data1-1 | 2-1 data
2. 0001 | 2011.01.01. Data1-2 | 2-2 data
4. 0003 | 2008.01.01 | Data1-4 | Data 2-4
5. 0003 | 2009.01.01 | Data1-5 | Data 2-5
7. 0003 | 1999.01.01 | Data1-7 | Data 2-7

Note that numbers have not only duplicates, but reanalysis, quadruplicates and n-plicates as well. All other data in the row may or may not be separate from the data in other rows with the same number.

I used

Select number, count (number) of SAMPLE
Group number
After count (number) > 1

It makes me only no separate numbers and their total number, each number only once. Any ideas how to get the entire file?

Hello

You can use the analytic COUNT function to do this:

WITH     got_cnt          AS
(
     SELECT     sample.*
     ,     COUNT (*) OVER (PARTITION BY number_col)     AS number_col_cnt
     FROM     sample
)
SELECT     id
,     number_col     -- NUMBER is not a good column name
,     date_col
,     data1
,     data2
FROM     got_cnt
WHERE     number_col_cnt     > 1
;

GROUP BY always returns exactly one row per group.
Most of the aggregate functions (for example, AVG, COUNT, MIN, SUM,...) have analytical equivalents, which can give you the same results without reducing the number of lines. The PARTITION BY clause from analytical functions is similar to the GROUP BY clause that used to aggregate functions.

Tags: Database

Similar Questions

  • Need help with SQL selection ID when the sequence does not match...

    I have the following dilemma:
    Database identifiers as follows:
    Incident #, case #, & sequence manufacturer
    example of
    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1

    Worksheet 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 2

    Sometimes the user will delete (say) 2 Record after creating a new Record 3
    The sequencing will therefore now as follows:

    Record 1
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 1

    Worksheet 2
    Incident_Number = 123456
    Case_Number = 1
    Part_sequence = 3

    Now it is no longer a Part_Sequence 2

    Need a SQL to select all records where the sequence of the maximum part > than Incident_number County | » -'|| Case_number

    I tried the following:
    select a.incident_number||'-'||a.case_number||'-'||a.part_sequence
    from chsuser.a_compl_summary a
    where a.entry_date >= '01-may-2011'
    and max(a.part_sequence) > count(distinct a.incident_number||'-'||a.case_number)
    I end up getting an ORA-00934: Group feature is not allowed here (emphasis on the portion (a.part_sequence) Max.

    Advice/suggestions

    Thank you
    select  incident_number || '-' || case_number || '-' || part_sequence
      from  (
             select  incident_number,
                     case_number,
                     part_sequence,
                     max(part_sequence) over(partition by incident_number,case_number) max_seq,
                     count(*) over(partition by incident_number,case_number) cnt
               from  chsuser.a_compl_summary
               where entry_date >= DATE '2011-05-01'
            )
      where cnt != max_seq
    /
    

    SY.

  • PDF forms have problems displaying text and only appears when the field is selected

    Hello

    I created pdf forms to be distributed to the clients of the company. But we have some people complain about the visibility of the text. When they work as a team, the pdf they receive from a third party often appears limes or no text, the text is only visible when the field is selected. I need to find a solution for this, because our company's products are based on this form.

    If there is any information addition that I must add to understand what is happening and how to fix it, I'll be happy to write it.

    In society, we all have mac and forms where innitially created in Adobe acrobat 9 pro, but we now have Adobe acropabt pro XI.

    Users of Mac and Windows systems.

    Thank you

    This is usually caused by the form is filled out and saved by a Mac user who uses the preview application to view the PDF file. More information is here: http://kb2.adobe.com/community/publishing/885/cpsid_88564.html

    It's a good idea to inform your users that Adobe Reader (or Acrobat) should be used to work with Forms.

  • Script where the zero is not displayed when no value is selected, indicates when a value of zero is selected

    How can I write a calculation script where the zero is not displayed when no value is selected, but when a value field null is selected as part of the zero calculation will show?

    Option 1 has a score of 0 value

    Option 2 has a value of 5 score

    When someone chooses option 1, I want the value 0 to appear at the cell of notation.

    Here is the script that I have so far:

    If (event.value == 0 | event.value == ") event.value =";

    OK, the custom calculation script could be:

    Get the value of the checkbox field

    var v = getField("checkbox1").value;

    Set this field value

    V = Event.Value = "Off"? "" : v;

    Replace "checkbox1" with the actual name of the checkbox.

  • What is the component used to select contact in the field "to:" when create new sms on BB OS 4.6?

    Does anyone know which component is used to select contact in the field "to:" when create new sms on BB OS 4.6? What is KeywordFilterField? If yes - how to customize it to make it look like the sms app? Can you give us some examples of code? I'm new in development for BB and I need this functionality in my application.  I will be very appreciate for any help!

    You will need to implement your own field full auto in this case.

  • How to control the selected area in the field

    I'm trying to find how to control him are selected a field so when the field is selected only a part of the field is highlighted. I can't find a way to do this other then stir in a small field within a field not selectable largr.

    Any suggestions on how to do it?

    Thank you!

    Hi crispoyz,

    You can override the drawfocus fields for this method.

    Try with this code. This is an example of code just to understand.

    class CustomField extends Field
        {
            int width = 100;
            int height = 100;
            String _text;
    
            public CustomField(String text)
            {
                super(Field.FOCUSABLE);
                _text = text;
            }
    
            protected void layout(int width, int height) {
                setExtent(getPreferredWidth(), getPreferredHeight());
    
            }
    
            protected void drawFocus(Graphics graphics, boolean on)
            {
                if(on)
                {
                    graphics.setColor(Color.GREEN);
                    graphics.fillRect(20, 10, getPreferredWidth()-50, getPreferredHeight()-30);
                    graphics.setColor(Color.RED);
                    graphics.drawText(_text, (width - getFont().getAdvance(_text))/2,(height - getFont().getHeight())/2);
                }
            }
            protected void paint(Graphics graphics) {
                graphics.setColor(Color.RED);
                graphics.drawRoundRect(0, 0, getPreferredWidth(), getPreferredHeight(), 20, 20);
                graphics.drawText(_text, (width - getFont().getAdvance(_text))/2,(height - getFont().getHeight())/2);
    
            }
    
            public int getPreferredWidth() {
                // TODO Auto-generated method stub
                return width;
            }
            public int getPreferredHeight() {
                // TODO Auto-generated method stub
                return height;
            }
        }
    

    Thank you.

  • Add "select all" to the context menu

    I find a bit of a pain to get the menu to select this command if I want to add select it all the windows explore right click contextual menu when I in yaws files (right hand).

    This is a tutorial on how to add "select all" from the context menu in Windows 7 - http://thecustomizewindows.com/2011/04/add-select-all-option-to-right-click-context-menu-in-windows-7/

    Jim

  • Vista and Color Laserjet 5 M reprints all when the printer is turned on?

    Vist and Color Laserjet 5 M reprints all when the printer is turned on?

    It is a new one on me. I installed the printer with a barrette SIMM Postscript so it would work even at all under Vista and now it prints well but insists on the fact that I have all re - print he has never seen a reason any whenever I turn the printer to print something again.

    XP he has never done that, but I've always had the document cannot print the error that I ignored as he did print correctly.

    Google has not really revealed anything?

    ?? Type response level 1 I was looking for... These printers are a full restart, test of memory and when it is off.

    But I think I solved it, spent some time on google and there was a suggestion on the spooler in vista, was something like clear keep printed documents or print spooling first, I went also to start printing after the last page. Who took care of a lot of it somehow. Not sure why the generic installation program would need to be changed here. Possible I did for me somehow when I was trying to get the thing to work with the PCL driver too.

    Then I noticed that whenever I turned on the printer it is printing a page of demo postscript, for some reason any, it is enabled by default in the SIMM option. Turn power off and now its not wasting so much paper now.

    So two things to look for in the computer and the printer.

  • How do I run a script only if the field is not empty

    How do I run a script only if the field is not empty

    Well well, thanks to you, I had a full date on separate days, the months and the years in different areas. But now, I have a problem, as PDF has several fields calculated with script if you enter the date calculated by all other areas, which have separated and undefinied gives me does not want to put this to not always use this field. I tried to put one conditional if else but I sale. Esto, this is what I'm wearing

    var datesol = event.value;//declaramos the variable

    If (datesol = "") {}

    this.getField('yearsol').value = "";

    this.getField('monthsol').value = "";

    this.getField('daysol').value = ""}

    else {}

    var array_datesol = datesol.split("/"); / / separamos esa con date the split funcio

    this.getField('yearsol').value = array_datesol [2];

    this.getField('monthsol').value = array_datesol [1];

    this.getField('daysol').value = array_datesol [0];

    With what they do not separate them now.

    Help please

    As mentioned, you cannot use

    If (datesol = "")

    because that sets the value of datesol to «» (you will need to double for the comparison operator =)

    If you want to run code only if it is NOT empty, while it takes:

    If (datesol <> "")

  • How to change existing keywords when the site is not in the bookmarks bar?

    I've implemented several shortcuts keyword for sites that I use frequently. Now, how can I change the keywords or URLS when the site is not in the list of bookmarks? Is there a master file Firefox for these access which can be edited by the user? Or another way to get to them?

    Not sure if it's the same on Mac OS x, but it is how it is done under Windows and Linux versions of Firefox.

    Bookmarks > organize bookmarks

    Highlight the bookmark in the right pane, and then click more at the bottom to see the keywords and Description fields for this bookmark.

  • HP ENVY x 360-15-w100nt: wi - fi connection slows down when the charger is not plugged

    Hello

    My wi - fi connection slows down when the charger is not plugged in. Correct the wireless lan drivers. So far, I appreciate all kinds of advice for this problem.

    Thanks in advance

    Hello @JohannNewma,

    Welcome to the HP support community! I read your post and wanted to tender hand can help you!

    I understand that you notice a decrease in speed wireless on the x 360-15-w100nt laptop computer ENVY when running off the battery voltage.

    You can check and adjust the power options on the system as it is probably trying to save battery power by reducing wireless performance.

    If you're still having problems, you can follow the steps described in this document to troubleshoot the network settings and internet wireless.

    Please get back to me how that happens. To show that you like, or are grateful for my post, please click the Thumbs up below.

    Thank you!

  • G42-461TU: Laptop hangs when the charger is not connected in

    Hi all

    I use HP G42 - 461TU Notebook.I have a problem with my laptop. He often gets crash when the load increases. Once when the charger is plugged in, it works fine. But when the charger is disconnected, it gets even once block. I thought it might be due to problem of memory and I added extra 2 GB DDR3 RAM too (totally 4 GB now), but the problem persists. Now I use windows OS 10, but I faced this problem with windows 7 too. Can someone please help me diagnose the problem with my laptop? Thanks in advance!

    Hi @Dinesh_R,

    Welcome to the HP Forums! I read your post and wanted to help.

    I understand that your notebook crashes when the charger is not connected. You can start with this document: computers HP - computer is slow (10 Windows)

    Let me know if that helps the problem.

    If this helps you to find a solution, please click on the button "Accept as Solution" down below in this message. If you want to say 'Thank you' to my effort to help, click on the "thumbs up" to give me congratulations.

    Kind regards

  • When the computer is not in use, it will sleep mode. When this happens, we do a physical stop to take control of the computer.

    When the computer is not used for more than ten minutes, the computer goes into "sleep" mode When this happens, we can use the computer and turn the computer off and restart it.

    Hello

    Please follow the methods.

     

    Method 1:

    Follow the steps.

    a. click the Start button.

    b. in the start search box, type power options , and then press on enter.

    c. click on change plan settings.

    d. Select the never option by using the drop-down menu for options, turn off the display and put the computer to sleep.

    Method 2:

    Follow the steps in the link.

    http://support.Microsoft.com/kb/930091

  • Our published application crashes when the user is not connected to WiFi

    It became clear after the last launch edition our published application crashes when the user is not connected to WiFi.

    This is a new one on us, someone at - it ideas?

    There was a bug in all versions of Viewer 24 and earlier that have arisen during the last iOS updated acme outside. If you upgrade to v25 or later version the issue will go away.

    Neil

  • Firefox seems to have recently developed seemingly random usually do not remember bookmarks, particularly when the pc does not stop correctly. Thank you

    Firefox seems to have recently developed seemingly random usually do not remember bookmarks, particularly when the pc does not stop correctly. Thank you

    If Firefox detects that the places.sqlite database is corrupted then Firefox can create a new database file and import bookmarks from a JSON backup that does not contain the most recent bookmarks (a new JSON backup is created when you run Firefox for the first time on a day), then you may lose the bookmarks in such a case.

    You can check for problems with the database places.sqlite file in the Firefox profile folder.

Maybe you are looking for

  • I created a new profile to resolve a problem of crash, and now I can't get to my favorites.

    Create the new profile has solved my problem of crash and I copied files and folders from my old profile to my new but I still can't have my favorites. What I am doing wrong?

  • I can't yet to erase an incorrect user name in the password file.

    I was using a web site for a long time. Suddenly the user name which is supposed to be stored in my file "password/username" does not work. I totally deleted this file web site. When I go to connect, it happens automatically with an incorrect usernam

  • Mirror or Flip image

    I have a HP Officejet 4620.  I need to print a transfer of iron for sewing.  By mode I should type what I want to print, and then select mirror image or return.  Heck, I'll be if I can find it anywhere!  HELP PLEASE!

  • Don't reinstall Windows 8 Pro OEM - no recovery partition / disk

    I have a Lenovo X 1 of carbon that I installed the Windows Technical Preview 10 on. In doing so, I formatted the drive hard so that I do not have the recovery partition as well. Now I want to reinstall Win 8 Pro OEM that came with. However, I don't h

  • DAQ cards not selectable, that listed in MAX

    I have (re-) installing a PXI-6122 card on my computer. The device is then entered in the measurement and Automation Explorer, but differently from what I'm used to: -It's another symbol than two PXI-6259 cards I have (see image below). -It is not po