3 display lines after each ID min

Hello

I have the below:

ID, name, Type
1, A, X
2, B, Y
3, C, Z
4, A, X
5, B, Y
6, C, Z
7, A, X
8, B, Y
9, C, Z
10, R, T1
11, S, T2
12, T, T3
13, R, T1
14, S, T2
15, T, T3

I do group by the name and type, take min (id) and display the first 3 of each of this id

O/P should be:

1, A, X
2, B, Y
3, C, Z
10, R, T1
11, S, T2
12, T, T3

Help, please
Appreciate the pointers on this.

Thank you
Mahesh

Hello

user13495266 wrote:
Thanks for the reply... I'll make sure that gives the definitions of table of my next post code...

Now, why not?
Change the data that I have (or Salomon) posted earlier.

Sorry to give this bad output... Group by should be also only the name and the type = X

Here is the modified and output desired

ID, name, Type
1, A, X
2, B, Y
3, C, Z
4, A, X
5, B, Y
6, C, Z
7, A, X
8, B, Y
9, C, Z
10, R, X
11, S, Y
12, T, Z
13, R, X
14, S, Y
15, T, Z

I have to group the name where type = X, take min (id) and display the first 3 of each of this id

O/P should be:

1, A, X
2, B, Y
3, C, Z
10, R, X
11, S, Y
12, T, Z

Help, please
Appreciate your response and your advice... Thank you

Don't query I posted earliker to produce these results? Display some data (CREATE TABLE and INSERT statements) where the queries posted alrteady give erroneous results and explain with specific examples how to get correct results in these places.

Do you mean that you want this line in the output:

`       ID N TY
---------- - --
         1 A X

because it has the lowest id of all lines with the same name and type = 'X', and the only reason for which you want to only these lines in the result:

`       ID N TY
---------- - --
         2 B Y
         3 C Z

is that they are 2 rows (in order by id) following after him?

If Yes, you need something like this:

WITH     got_min_id     AS
(
     SELECT       MIN (id)     AS min_id
     FROM       table_x
     WHERE       type     = 'X'
     GROUP BY  name
)
,     got_x_cnt     AS
(
     SELECT     x.*
     ,     COUNT (m.min_id) OVER ( ORDER BY      id
                                          ROWS BETWEEN  2 PRECEDING
                                   AND     CURRENT ROW
                          ) AS x_cnt
     FROM           table_x     x
     LEFT OUTER JOIN  got_min_id  m  ON   x.id  = m.min_id
)
SELECT     id, name, type
FROM     got_x_cnt
WHERE     x_cnt     > 0
;

Tags: Database

Similar Questions

  • Insert a blank line after each line grouped

    Oracle 11.2.0.1

    Windows XP

    I need to create a table (who have more to exported to the Excel SQL Developer) something like this:

    The user Scott Table Emp


    create the table temptbl as

    SELECT

    -case when lead (deptno) OVER (ORDER BY deptno) = deptno then empno otherwise null end AS empno.

    -case when lead (deptno) OVER (ORDER BY deptno) = deptno then ename otherwise null end AS ename.

    -case when lead (deptno) OVER (ORDER BY deptno) = deptno then job otherwise null end AS work,

    -case when lead (deptno) OVER (ORDER BY deptno) = deptno then null deptno otherwise end up LIKE deptno

    WCP

    Table created.

    SQL > select * from temptbl;

    EMPNO, ENAME, DEPTNO JOB

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

    7782 CLARK MANAGER 10

    PRESIDENT OF 7839 10 KING

    7566 JONES MANAGER 20

    FORD ANALYST 20 7902

    7876 ADAMS CLERK 20

    SMITH CLERK 20 7369

    7521 WARD SALESMAN 30

    7844 TURNER SELLER 30

    7499 ALLEN SALESMAN 30

    EMPNO, ENAME, DEPTNO JOB

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

    7900 JAMES CLERK 30

    MANAGER OF 7698 30 BLAKE

    14 selected lines.

    SQL >

    But it is not giving me the last row of deptno.  If I have to display the data on sqlplus then I can use break on jump 1, but since I create my correct query table (around 10 K lines), I just want to insert a blank line after each data grouped.

    Thank you.

    Select empno, ename, job, decode (empno, null, null, deptno) deptno emp

    Group by grouping sets ((empno, ename, job, deptno), deptno)

    /

    EMPNO, ENAME, DEPTNO JOB
    ----- ---------- --------- ----------
    7782 CLARK MANAGER 10
    PRESIDENT OF 7839 10 KING
    7934 MILLER COMMITTED 10

    SMITH CLERK 20 7369
    7566 JONES MANAGER 20
    7782 CLARK MANAGER 20
    SCOTT ANALYST 20 7788
    7876 ADAMS CLERK 20
    FORD ANALYST 20 7902

    7900 JAMES CLERK 30
    7499 ALLEN SALESMAN 30
    7521 WARD SALESMAN 30
    7654 MARTIN SALESMAN 30
    SALESMAN 7698 BLAKE 30
    7782 CLARK MANAGER 30
    7844 TURNER SELLER 30

  • gray line after each line of list field

    Hi friends,

    I would like to draw a gray line after each line of listField I use folowing d

    graphics.setColor (Color.LIGHTGREY);

    graphics.drawLine (0, y, Graphics.getScreenWidth (), y);

    then the line is gray (the color of the text)

    then as the then-jeutiliser

    graphics.setColor (Color.LIGHTGREY);

    graphics.drawLine (0, y, Graphics.getScreenWidth (), y);

    graphics.setColor (Color.BLACK);

    It works, but, more early when the update comes to rowing of the color of the text will change to white but now always the text is black

    So, how can I draw a gray line after each listfield rw without affecting the texts

    You must save the original color and reset it after drawing like that.

    int origcolor = graphics.getColor(); 
    
    graphics.setColor(Color.LIGHTGREY);
    graphics.drawLine(0,y,Graphics.getScreenWidth(),y);
    
    graphics.setColor(origcolor);
    
  • Introduce the empty line after each subtotal

    I want to add a blank line after each subtotal for readability. I thought that Char (13) would do the trick. You have any ideas on how to achieve this?

    Thank you
    Dinesh.

    In the PivotTable, you can do it in double layer on the column that you are dissociation on. Then in the ownership of the sum of the column in double, specify label only. Hide duplicated columns.

    HTH
    -Prakash

  • Line does not come after each row of the list

    Hello

    I show a list in my current application. In the list, I paint a line after each line. Just a line of string, I add in each line. Now when I'm checking the list, on some devices, lines are coming. As in Bold 9790, after each line, a line is added. But in the Torch 9810 and curved 9320, line is not there. I don't get why this different behavior for different devices.

    Can someone please help.

    Here is my code:

    public class ListCallBack implements ListFieldCallback{
    
            public void drawListRow(ListField listField, Graphics graphics, int index,
                    int y, int width) {
    
                String text = "xxxxxxx";
                graphics.setFont(FONT_FAMILY_1_SF_AS_08);
                graphics.drawText(text, 10, y, DrawStyle.ELLIPSIS, width);
    
                if (index != 0) {
                    graphics.setColor(Color.BLACK);
                    graphics.drawLine(0, y-12, width, y-12);
                }
            }
    
            public Object get(ListField listField, int index) {
                // TODO Auto-generated method stub
                return mAccounts[index];
            }
    
            public int getPreferredWidth(ListField listField) {
                // TODO Auto-generated method stub
                return screenWidth;
            }
    
            public int getPreferredHeight() {
                return getContentHeight();
            }
    
            public int indexOfList(ListField listField, String prefix, int start) {
                // TODO Auto-generated method stub
                return listField.getSelectedIndex();
            }
    
            }
    }
    

    Thank you...

    The best result I wanted to say, variable height from station to station. So currently I use the line height and made changes accordingly.

    Here is my Code:

     Font f = FONT_FAMILY_1_SF_AS_08;
                graphics.setFont(f);
                int h = f.getHeight();
                int height = (listField.getRowHeight() - h)/2 ;
                y += height;
                graphics.drawText(text, 10, y, DrawStyle.ELLIPSIS, width);
                if (index != 0) {
                    graphics.setColor(Color.BLACK);
                    graphics.drawLine(0, y - height + 1 , width, y - height + 1);
                }
    

    It worked properly. Thanks a lot Peter and Simon.

  • queue a file by adding spaces after each line

    Hello

    I am the result of a sql queue in a csv file in the linux operating system. But the file generates a lot of blank lines after each line. How can this be eliminated in queue

    Thanks in advance

    SAS

    By default, SQL * more spool empty right pads each LINESIZE value line. Add

    SET TRIMSPOOL ON

    to your script.

    SY.

  • Change the value of the balance after each line

    Hi all
    I do a sql statement returning the vacation schedule for this year for all employees.
    The query displays the name, from date to date, the balannce of vacation of the employee, the number of vacation days and the balance after the holidays
    : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Name - Of - from Date to Date - holiday balance - vacation days - after sale: -.
    Alan--------------------------June 2010--------------- 15-July 2010 ------------68 ------------------------33 ---------------------35 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Tom-------------------------June 2010--------------- 12-August 2010 ------------ 177 ------------------47 ----------------------130 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Adam------------------------July 2010--------------- 12-August 2010 ------------ 73------------------------- 26 ---------------------47 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Adel-------------------------August 2010--------------- 05-August 2010 ------------158 ---------------------5 --------------------153 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Alan ------------------------August 2010--------------- 16-September 2010 ------------ 68------------------ 19 ---------------------49 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Tom ------------------------September 2010--------------- 09-September 2010 ------------177 -----------5 ---------------------172 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Suzy-------------------------September 2010 ---------------30-September 2010 ------------127------------- 19---------------- 108 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Adel-------------------------September 2010 ---------------16-September 2010 ------------158------------ 5 -------------------153 : -------------------------------------------------------------------------------------------------------------------------------------------------------
    Adam -----------------------November 2010--------------- 09-December 2010 ------------73--------------- 19--------------------- 54 :--------------------------------------------------------------------------------------------------------------------------------------------------------
    Tom ------------------------December 2010 ---------------05-January 2011 ------------ 177 -----------------17 ----------------160 :--------------------------------------------------------------------------------------------------------------------------------------------------------

    My problem is that the balance of vacation is not correct after each retrieved line. It should be updated after the extraction of all ranks. My query is:

    {code
    Select Emp_ar_name_full Date_from Date_to, Vacation_balance, number_of_days, BALANCE_AFTER vacation_balance-number_of_days
    of HRS_V_EMP_VACATIONS_schedule@pms VAC,HRS_V_EMP_BASIC_INFO@pms emp
    WHERE EMP. EMP_ID = VAC. EMP_ID
    AND dept_id = 7
    And sect_id = 11
    and To_Number (To_Char (sysdate, 'yyyy')) = 2010
    and EMP_ACTIVE = 'Y '.
    AND DATE_FROM > = SYSDATE
    order of Date_from
    }

    I want to change the query so that the vacation balance will be updated after the extraction of all the ranks of an employee
    Thanks in advance

    Published by: [email protected] on June 7, 2010 14:33

    Can change this:

    vacation_balance-number_of_days BALANCE_AFTER

    TO:

    vacation_balance - sum (number_of_days) over (partition by order of emp_ar_name_full of date_from) BALANCE_AFTER

    For an example, please post a small test case.

    Kind regards
    Rob.

  • How to display data series changed after each step in labview gui, that is to say after the match point fantasy, after substring etc.

    Hi, I have a labview GUI that receives data serially through VISA and basically chops to the strings and realize games until I have values that I'm looking for. I have then convert Ascii string in decimal and feed the new values to a waveform. However, I discovered that some of the output values are incorrect. I checked this by pulling data through Realterm.

    Is it possible that I can see the modified data after each step in the user interface so that I can find where the problem is? I created indicators after each step, but they do not display data, I guess that its because the data is moving too quickly.

    I am very new to labview and struggled through every bit of this GUI, as none of you regular posters know. If you can suggest a solution, please know that I will probably ask more fundamental questions in order to implement your solution.

    I enclose my GUI with a screenshot of the same data through the Realterm. Basically any where you see xxxx TR TR or W xxxxW, know that it is the data between them is to say xxxx that corresponds to the data of interest. Everything else is ignored.

    I suspect that the problem lies in the string to decimal conversion and where 3 digit values increase to 4-digit values. That is, all values of less than 850 are correct but it is the maximum value is reached. My values are expected to reach 2500. Any help would be greatly appreciated.

    You have other debugging tools available to you.  You can use the run culminating to slow down the code and show you the data flowing from each wire.

    You can create a Subvi, which takes the data of each wire and written to a log file if you can review it later.

    You give not the screenshots to your message.

  • Police have a capital 'A' with a carat on top after each period and 2 spaces. How can I fix it?

    Sometimes, I get this when I get emails. If I send an email and then go to the folder "sent" to see what I sent, there is a capital A with a carat on top after each sentence (but it seems that when I finished the sentence with a period and 2 spaces.)

    I tried to change the fonts, but that doesn't seem to help. I had this problem with an older version of Thunderbird and hope go away when I upgraded my OS (Linux Mint - opportunity to Ubuntu 10.4). I suspect that what is originally it was made more when I transferred my files to the new Thunderbird.

    Thank you.

    Looks like the incorrect character encoding is used.

    What character encoding you have set here:
    Edit > Preferences > display > formatting tab
    Click on the button "Advanced".

    See my example below image

    You can edit an image showing what you have selected, is much easier to type this.

    What is only a problem with mail in the "sent" folder or also with mail in other folders?

    Select the e-mail in the "sent" folder
    Click on "other actions" > view source
    or view > message source
    or
    CTRL + U

    What is in the source code for these lines:
    example:
    Content-Type: text/html; charset = windows-1252
    Content-Transfer-Encoding: 8 bit

    You can try to select email then:
    View > character encoding
    What is selected?
    Try another encoding, note that this will be only temporary while e-mail.

    additional help:
    http://KB.mozillazine.org/Font_settings_in_Thunderbird
    https://support.Mozilla.org/en-us/questions/989709
    https://support.Mozilla.org/en-us/questions/993631

  • Firefox cleans the exceptions list 'Allowed Sites - Installation of modules' after each reboot.

    Firefox cleans the exceptions list 'Allowed Sites - Installation of modules' after each reboot. I tried the new own profile - everything works fine. I don't want to installation and implementing all addons after reset of profile, so try to understand the problem.

    Compensation for the "Site Preferences" (in the "Clear recent history" or Ctrl + Shift + Delete) same for the "last time" helped.

    (permissions.sqlite contained an empty table instead of default lines)

  • El Capitan 10.11.2 disconnects from the network of Canon printer macbook pro after each use but with the same OS version iMac remains connected

    How to prevent my Macbook Pro El Capitan 10.11.2 going to disconnect my network printer Canon?   My iMac running the same OS version don't unplug and behaves like any normal wireless connection.  I deleted the printer and added back, reset printing, etc. nothing works.  Given that the Mac is 6 "each other and 5 feet of printer during the last test, it must be something specific to the Macbook.  The Macbook identifies the printer after each reboot the printer as printer Canon right, but once the task is completed does not have the printer.  Everything is on the same wireless network. Computer Windows also recognizes the printer and it keeps alive after printing.

    Please read this message before doing anything.

    This procedure is a diagnostic test. It is unlikely to solve your problem. Don't be disappointed when you find that nothing has changed after you complete it.

    The test is intended to determine if the problem is caused by a third-party software that loads automatically at startup or logon, by a device, by a police conflict or corruption of system files or some system caches.

    Disconnect all devices wired except those required to test and remove all the expansion cards from secondary market, as appropriate. Start in safe mode and log on to the account of the problem.

    Note: If FileVault is enabled in OS X 10.9 or an earlier version, or if a firmware password is defined, or if the boot volume is a software RAID, you can not do this. Ask for additional instructions.

    Safe mode is much slower to boot and run as normal, with limited graphics performance, and some things work at all, including an audio output and a Wi - Fi connection on some models. The next normal boot can also be a bit slow.

    The login screen is displayed even if you usually connect automatically. You need your password to log on. If you have forgotten the password, you will have to reset it before you begin.

    Test in safe mode. Same problem?

    After testing, restart as usual (not in safe mode) and make sure you always have the problem. View the results of the test.

  • DSC-WX350 shows 'unable to display' remains after the withdrawal of the card photos

    I'm having a problem with the DSC-WX350 seeing "ghosts" of the pictures after having been withdrawn to a computer.

    If I pop the camera card, stick it in a card reader and move photos the camera on my computer, as soon as I put the card in the WX350 seem to see fake photos files moved: it acts as if they were still there (info, date taken, keeps in the County of photo, etc.) but only shows an error "Unable to display" gray.

    I then manually delete each erroneous entry manually. As you can imagine, making whenever I have move photos from your camera is a pain in the *. I've looked through all the folders on the card and see anywhere that would be markers of remains of file or something else because of this problem. Any ideas why this happens?

    (FYI, the card has been formatted freshly correctly before using it in the camera.)

    Thanks advance.

    Can anyone offer help?

    Per this message on the card need to be formatted, I made several times now to try to circumvent the problem: formatting through the camera, formatting through the computer, formatting the computer, then the camera... After each time the test photo, I take and then remove while the card is located on the computer returns an error "Unable to display the image" ghost once the card in the camera.

    This is ridiculous. I will not be manually re-deletion of photos I moved your device every single timejust to avoid this * error. What happens here?

  • Manipulation of table (delete the lines which are > lines after them)

    I have a table of entry I want to manipulate.

    We measure a rotation device.  In the measurement sequence we want to display the data on a slope that is constantly growing, although when we let off the coast of the acceleration of our mobile device at the end of the test, we end up with a higher torque #s at the beginning of the sequence of RPM... which blurs our line of slope on our chart.

    For example, see the PNG attached on the table of torque/RPM torque.  I need to be able to cut the 2 first lines of the table that we need go less and more general in the line of torque sequence.  Throughout the test, we have a number of line 10 for example couple that is greater than the value of torque on line 11, so that we would need to cut the value of torque in line 10.

    I have attached the vi sub that I plugged in order to try it, but can't make it work.   I don't have to sort the table, but to remove the lines that exceed the lines after them... relatively to the value of rpm decreases constantly.  If I have a pair of value 2340/1869 in the row 1 & 276/1839 in row 2, I need rank 1 deleted.  But if I have a pair of value of 2509/1704 in row 12 & a pair value of 2493/1689 in the 13th row, I don't want to let the value of torque in (if possible) because it is a realistic appearance of the torque curve captured during the sweep of the power of the test.

    Any ideas?

    ready!

  • I'm trying to generate a table of random numbers 30. After each 5 readings a new vi must open and indicate to the user than 5 readings were made. and continue with the generation of the table again.

    because I don't have a sensor now, I am currently generating a table of random numbers 30. After each 5 readings a warning should be given to the user 5 readngs are completed. This cycle must be repeated. the size of the table is 30.

    Please help me, waiting for response as soon as possible.

    Once I have the transducer, I'll take 30 analog samples and then after each 5 smaples this wraning will be displayed din a new VI

    Use a while loop with a delay time representing your sampling interval.

    Use is equal to the count Terminal to see if 4, then 4th iteration = 5th sample.

    Use a box structure. The real deal will only run on the 4th iteration.

    In the case of true place a Subvi with your message of your choice in the front panel. Go to the properties of the VI window and set ' open the front panel when it is called.

    The condition to closing of attention is not given to your description.

    Consider that rather than usign a Subvi to do this, you can use the "dialog box one/two/three button" or "display message" live in the palette "user interface and dialogue."

    Please try it out and send your own VI. Do not provide us with a working solution.

    Kind regards

  • plot update after each iteration

    Hello

    I have an example of data code where I collect data on different devices.  Can you help me to update "GRAPHIC 2" to display all of the plots on this graph."  However, I would like FIGURE set 2 updated after each throw outside of the loop.  [After the 3rd iteration of the outer loop (defined by "outer loop"), "GRAPH 2' should therefore 3 plots and so on..."]

    Thank you

    hiNi.

    Hello hiNI

    Do you want something like that?

Maybe you are looking for

  • Portege M200: recovery discs and Win Xp tablet

    I had to replace my hardrive on my tablet now only to discover. I can no longer use the tablet like I have no drivers or software nesecary. I was on the web site of Toshiba, but you can't find what I'm looking for. I now use the Win xp on it media ce

  • processor i3 HP 250 G3: blue screen Hp 250 G3

    Salve,comunico has well if riscontrato problemi con UN G3 250 Hp portable improvvise schermate blu queste sono dovute AI Driver WiFi RALINK, currently available sul sito Hp driver (oggi 8 July 2015).Oggi Ancora non ho avuto possibility to find a comp

  • Network problems when mixed with computers based XP - Win 7 computer help?

    My network functions end when all computers are based on XP, but when a computer is Windows 7 wireless I discovered only two of three computers. There is no other variables.

  • Digital camera does not load on laptop.

    When I plug my digital camera into a usb port on my laptop, it recognizes the camera but won't show the screen asking me what I want to do with photos. It has worked before, but now I can't load my photos. What can I do?

  • Vistalizator is legal?

    Hello! I would like to know if "vistalizator" is legal? (http://www.froggie.sk) Vistalizator overrides the limit of one MUI language on non-Ultimate editions. It uses the official Microsoft MUI packages.