Top 5 and bottom 5

Hi all

Can someone help me solve the following problem...

How to get the top 5 and bottom sale 5 pounds in a single query

For example:

Name of the book of No.sold
----------------------------
A 45
78 B
C 8
D 6
T 66
E 33
AA 35
AB 95
CA 51
5 AD
AE 42

desired output:

Top 5 bname | bname down 5
--------------------------------------------
AB AD
E C
T C
E AC
BIS BIS

Thanks in advance
Sana

As, in general, more than one book can have no_sold even, more than 5 books can have no_sold up/down. If you want all the 5 up and down the sale of books, use:

with t as (
           select  book_name,
                   no_sold,
                   dense_rank() over (order by no_sold desc) rnk_top,
                   dense_rank() over (order by no_sold) rnk_bottom,
                   row_number() over (order by no_sold desc) rn_top,
                   row_number() over (order by no_sold) rn_bottom
             from  books
          )
select  t1.book_name,
        t2.book_name,
        t1.no_sold top_no_sold,
        t2.no_sold bottom_no_sold,
        nvl(t1.rnk_top,t2.rnk_bottom) rank
  from      t t1
        full join
            t t2
          on (
                  t2.rn_bottom = t1.rn_top
             )
  where t1.rnk_top <= 5
    and t2.rnk_bottom <= 5
  order by nvl(t1.rn_top,t2.rn_bottom)
/

BO BO TOP_NO_SOLD BOTTOM_NO_SOLD       RANK
-- -- ----------- -------------- ----------
AB AD          95              5          1
B  D           78              6          2
T  C           66              8          3
AC E           51             33          4
A  AA          45             35          5

SQL> 

If everything you want all high-low 5 is sold of books:

with t as (
           select  book_name,
                   no_sold,
                   row_number() over (order by no_sold desc) rn_top,
                   row_number() over (order by no_sold) rn_bottom
             from  books
          )
select  t1.book_name,
        t2.book_name,
        t1.no_sold top_no_sold,
        t2.no_sold bottom_no_sold,
        t1.rn_top rn
  from      t t1
        inner join
            t t2
          on (
                  t1.rn_top <= 5
              and
                  t2.rn_bottom <= 5
              and
                  t2.rn_bottom = t1.rn_top
             )
  order by rn
/

BO BO TOP_NO_SOLD BOTTOM_NO_SOLD         RN
-- -- ----------- -------------- ----------
AB AD          95              5          1
B  D           78              6          2
T  C           66              8          3
AC E           51             33          4
A  AA          45             35          5

SQL> 

SY.

Tags: Database

Similar Questions

  • TopDown approach and bottom-up Web services

    Hello

    It's a simple question, I am new to bpel...
    What are the merits and demerits Web services top-down and bottom-up approach.
    everything can give correct url.



    Thank you
    Prasad

    Bottom-up: firstly to create the java interface and POJO, then generate the WSDL tools.

    Top to bottom: Handcraft the WSDL, then generate java and POJO interfaces using tools.

    The two approaches has its own merits / demerits. You must choose what your business needs. Google for more information.

  • Since then went black download firefox 4 top and bottom of my screen and I can barely see the button/arrow to the left

    Question
    Since then went black download firefox 4 top and bottom of my screen and I can barely see the back/arrow button, if I can not go back to 3.6 and you'd have to show me how, step by step without computer talk if it is not possible for you that I return to internet explore... cordially chris williams

    You are welcome. I'm glad that you were able to find a solution with the information provided by the contributors here.

    So that other users can find solutions to Firefox previously asked take charge of issues, please take a few minutes to come back on the forum, log in, then click 'resolved' next to the answer above you helped more to find a solution. Thank you.

  • Photosmart 6510: lines horizontal and top and bottom of page when scanning

    Hello

    Scans of the bucket of my Photosmart HP 6510 leave a horizontal line at the top and bottom of the page.

    I tried to adjust every page that I scan to align as straight as possible on the glass and this sometimes helps a bit.

    I am able to bypass the lines in culture to, but would prefer to find a real solution.

    Any help would be appreciated because I don't know a lot about the scanners, thanks!

    I've included a sample page below (the mark on the right side is not dirty glass, it has been a staple in the page):

    Welcome to the HP community @lgilb01,

    I wanted to tender hand to respond to your message on the lines that you notice when you scan to scan in your Photosmart 6510 bed. It seems to me that there could be some light enter when performing the analysis, causing lines. If you are only scanning one page at a time, the lines should not appear as they are now.

    Here is a troubleshooting guide for you to try. If the lines do not fade, contact HP directly to see about a replacement printer.

    HP Photosmart 5510, 6510 and 7510 e - all-in - One Printer Series - vertical stripes, lines or scratches in Copies or scans

    Tip: Make sure that the printer is plugged directly into the wall, avoiding bars power and surge protectors. This ensures that the printer is full on.

    Testify of my answer by pressing the thumb in the air below and hit the "accept as Solution" button, if I have you helped a resolution!

    I hope I helped!

    Contact HP:

    Step 1. Open the link: www.hp.com/contacthp/
    Step 2. Enter the product number or select Auto detection
    Step 3. Scroll up to "still need help? Fill out the form to select your contact options.
    Step 4. Scroll down and click on: contact HP options - click Get phone number
    File number and phone number are displayed.

  • Portrait mode, how to drag a program window to the top and bottom of a window and have it snap.

    Maybe it's more of a feature request: Windows 7 has a component feature snap where you drag a window of program on the side of the screen and it will maximize this measure only half of the screen.  I love this feature and use it often to keep my office in order.  I recently turned to another monitor that I keep in Portrait mode, but the nod to works only on the sides.  Good if I had a big enough screen, but I really want to align with the top and bottom of the screen.  Please advise, thank you.

    Interesting idea! To get to the right people at Microsoft, please click thegive us your comments. Help improve Windows 7 link under ads at the top of the main page of the forum, or go to the page give us your comments for Windows 7 . Boulder computer Maven
    Most Microsoft Valuable Professional

  • Remove the big black bar at the top and bottom of Office

    original title: my desktop image now has a big black bar at the top and bottom. How can I get rid of this?

    The image filled my monitor yesterday. Today, I have a big black bar at the top and bottom. How can I get rid of this?

    1. Right-click on your desktop, choose Customize.
    2. At the bottom, click background.
    3. Finally, click on the Position of the image and choose Stretch or complete, what you prefer.
    4. Click on save changes.
    If this isn't the cause, you could also do that you use the full resolution of your monitor.
    1. Right-click on your desktop, choose the resolution of the screen.
    2. Make sure that you use the recommended resolution.
  • How to crop without black at the top and bottom

    Hello

    I try to crop a video. I go to Effects > video effects > transform > crop and under the effects of the controls, I put 20.0% on top and 12% on the bottom because that's how I want the cropped video. When I export the video it is always black on the top and bottom. How crop and export this video without that there is black at the top and bottom (and also to reduce the height of the video, take a part from the top and down)? Thank you!

  • Unable to get the elements placed at the top and bottom of the cell of the table with vertical-align

    Hello

    I have a three-day educational courses in the list table. In each cell, I have the title of the presentation at the top with the name of the speaker below. Because some titles are longer than others, the line grows (rightly) as longer securities are covered in Word. So far so good. Now, I want all the titles to always start at the same distance from the surface of the cell (I use padding 2px) and names of speaker all be equidistant from the lower border, (i.e. 2px).

    I tried to place the title elements with < span style = "vertical-align: top" > </span > presentation title

    and the name of the speaker as < span style = "vertical-align: bottom" > name </span > Speaker

    and I tried the same method with < div > and < p > tags. Items don't move. Can someone tell me how to make the names of the speakers will be all aligned at the bottom of each cell?

    Here is an example of the code table I've tried:

    (Thanks!)

    < table style = "text-align: center;" do-family: Arial; background-color: #f7d49c; "border ="2"bordercolor =" #467E9F "cellpadding ="2 ".

    "cellspacing ="0"width ="900">"

    < tbody >

    < b >

    < td width = "300" > < span style = "" vertical-align: top; "> This is a short title </span > < br / >"

    < span style = "vertical-align: bottom" > name </span > < table > Speaker

    < td width = "300" > < div > is the title of another presentation, which is really long because some of the presentations have titles like that < / div > < br / >

    < div style = "vertical-align: bottom" > Speaker name < / div > < table >

    < td width = "300" > < span style = "vertical-align: top" > This is yet another presentation with a semi-long title </span > < br / >

    < span style = "vertical-align: bottom" > < table > </span > Speaker's name

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < / tbody >

    < /table >

    By default, the content of the table cell is average aligned.  You need not do anything.

    If you want your cell vertically aligned up or down, you can specify it in your CSS.  These effects all the text inside the cell.   It's all or nothing.

    Some text that is aligned at the top Some bottom-aligned text

  • I try Ben numbers several pdfs at the same time.  Once I did this, I'll and look and from the second page, the Ben numbers appear at the top and bottom.  I want only the bates numbers to appear at the bottom.  How can this be a gift

    I try Ben numbers several PDFs at the same time.  Once I have a result, from the second page, the Ben numbers appear at the top and bottom.  I want only the bates numbers to appear at the bottom.  How is that possible?

    Hey Bethany,.

    Please try again to implement numbering following the steps in article Acrobat bates help | Add headers and footers Bates numbering in PDF format

    Make sure that you apply for Bates numbering in the foot of page, as shown in the screenshot below.

    Kind regards

    Nicos

  • Using the PNG format with maximum width without clipping the top and bottom of the image?

    I use PNG format to preserve transparency and shadow, I am trying to integrate to give the illusion that this slab object is floating above the other layers.  First I tried file > place to position the menu object on edge of header/beginning of the content.  This leaves no option to force the image to span the width of any screen.  I need that I tried to use object > fill > and then clicking on the maximum width of the rectangle (which solves the problem of maximum width), but now I am facing a problem of cutting top and bottom of the image.  The next thing I can think of is to go back to Photoshop and to distort the image, so it is not as big.  In my view, there must be an easier way to achieve will not also give my image an abnormal appearance.  Thoughts?  Thanks in advance.

    Thanks, that's useful.  I also found that I've cropped for a large part of the canvas.  After the increase the surface of the canvas AND fill everything is fine now.  I think that your suggestion may help with the problem of affect scroll I will have when you use different resolutions. I will try to set the size in a single dimension (height) so that different resolution screens see the same scrolling actions.  Mylenium thanks!

  • Can I define the contour of an object to be on top / face and filling on the bottom / back?

    Can I define the contour of an object to be on top / face and filling on the bottom / back?  I've asked this question before and told to go to the appearance and drag the background and outline around as if they were a layer, but this did not bring my race to the top of the image.  I did this wrong somehow, or is there another method?

    I was just thinking ' didn't I said this the other day... ". "in any case...

    This is an object with a dark gray line and a red fill. the race is in front of the filling. any random object that you draw will be the race before filling unless you tell her not to be. You can say that the race is forwards here because it extends also on each side of the framework encompassing:

    Here, the situation is reversed. Note the appearance palette. You can fill is in the front because it now covers half of the race which extends inside the frame enclosing:

    If this is not the behavior you're seeing, it's time to refer to the list of Jacob.

  • IE defining the additional margin at the top and bottom of page using CSS

    Hello

    I am struggling with getting a site to look right in Internet Explorer.

    I wonder if anyone knows the answer or has some ideas to help me solve the problem...

    I use the headers and footers on a background image (with repeat-y on the style sheet) to give me a picture frame effect. You can see what it's supposed to look like below, using Firefox, Opera or Netscape browsers.

    http://www.sueharrington.co.UK/layout_tmpl_test.htm

    However, in Internet Explorer, I get two problems.

    1. the extra space at the top and in bottom of header and footer gifs.
    2 bar (middle of the page) seems to have space for additional margin in IE, causing it to wrap around.

    I managed to product another site where he works, but cannot see what is different about this one.

    http://www.enscott.co.uk/indexb.htm - work in IE and Firefox

    Someone at - it had indications or experienced this problem?

    Thanks in advance

    Neil

    (I use a Dreamweaver template to generate the pages, but cannot see this difference make?)

    It solved! - Or at least got a job.

    This came from the discovery of EI mismanages the following values

    margin-bottom
    height

    Basically low-margin or abbreviations seem to be ignored on the labels of stylesheet id (#). To test this, compare the following on IE and another browser (Firefox, for example)

    To see this, write this stylesheet

    {body
    background-color: #FFFF00;
    margin: 0;
    }

    {#wrapper}
    background-color: #FF0000;
    Auto margin: 100px;
    height: 1000px;
    Width: 770px;

    for this html code





    Display in IE and Firefox (or another browser)

    Firefox poster correctly a red box on a yellow page with 100px margin top and bottom - that is to say however has a zero at the bottom.

    Then apply the 100px high and the bottom margin to the "body" as below, leaving unchanged #wrapper.

    {body
    background-color: #FFFF00;
    Auto margin: 100px;
    }

    Firefox is unchanged: he seems to ignore the margin-top on the body.

    IE now shows a box with a tope 200px margin and a lower margin of 100px.

    The other interesting thing appeared with the parameter "size".

    If you insert a header or a footer background URL in a stylesheet, Firefow requires that you leave space for your background, or it does not show.

    So for a 16px high gif, use the following text in the style sheet. (It used to a gif in footer)

    #footer {}
    background-image: url (.. / images/bg_bottom.gif);
    background-repeat: repeat no.;
    height: 16px;
    Clear: both;
    }

    IE requires the value of 'height', but it is not guaranteed. (Even 1px or 1%) - if it is present, it works.

    Unfortunately, this does not solve my pixels very little space, but made me think - if the margin is not properly handled on the tags "#", if I do the

    the same color as the outside of the screen, it will not appear. This is easily done by using the following

    background-color: #999999;

    If my final CSS stylesheet looks like this

    / * to position the image in the browser * /.

    {body
    background-color: #999999;
    margin: 10px 0;
    padding: 0;
    }

    (/ * to contain and center of the page and product image sides) * /.

    {#wrapper}
    Width: 810px;
    Auto margin: 0;
    background-image: url (.. / images/bg.gif);
    background-repeat: repeat-y;
    }

    / * to keep the photo album frame * /.

    #banner {}
    height: 15px;
    background-image: url (.. / images/bg_top.gif);
    background-repeat: no-repeat;
    }

    / * to keep the background image * /.

    #footer {}
    background-image: url (.. / images/bg_bottom.gif);
    background-repeat: repeat no.;
    height: 16px;
    background-color: #999999;
    Clear: both;
    }

    With the html as follows







    content of the page here






    This gives the desired frame "image". Still not 100% sure why the problem of initiall which happened, but this seems to fix.

    The final page can be seen at

    http://www.sueharrington.co.UK/layout_tmpl_demo.htm

    Thanks for your help.

    See you soon

    Neil

  • How can I get the scroll bar to go to the top or the bottom of the page with a right click command?

    When I right click on the scroll bar nothing happens. I have to repeatedly turn the mouse wheel to get to the top or the bottom of the page. I just changed from the Explorer. I'm used to be able to do this. It's a lot less frustrating and time-consuming. I hope someone can help. Thank you.

    Unless an extension (to my insue) provides this functionality, there is no context for that Menu item. Press the keys Home and end the keyboard for up to the top and down.

  • I would like to have at least 1 of my toolbars that are displayed at the bottom of my browser open screen. How can I move a toolbar from the top to the bottom of the page?

    I would like to have at least one of my toolbars that are displayed at the BOTTOM of my browser open screen. How can I move a toolbar from the top to the bottom of the page? I don't want to do this by using an extension, and when I read about the extension, I really have not seen how it would move the toolbar to the top-down any browser page open.
    Thanks in advance for the supply, the answer and the procedure to get this accomplished.

    You can't drag an entire toolbar to the bottom of the window. The Bar of the Addon is a "toolbar", drag whatever you want from the Palette to customize or a toolbar up to the bar of the Addon.

  • Add new instances to the top of the bottom of the list (table or group) vs

    Is it possible to add new instances (i.e. of a table row, or a subgroup) to the "top" of the bottom vs list? New instances are usually added at the bottom of the group, but I have a case in which I am trying to insert new instances of more recent story of Job, so have the instances added at the top of the list is more advantageous.

    Please advise and thanks in advance!

    Hello

    to add an instance on the top use the menthod of insertInstance() instead of addInstance().

    Table1._Row.insertInstance(0, true);
    

Maybe you are looking for