Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:49:58+00:00 2026-06-13T21:49:58+00:00

I have a table as below Schema: ID | Category | Keyword | Bid

  • 0

I have a table as below

Schema: ID | Category | Keyword | Bid Price

Write a sql to fetch out top 5 keywords based on the bid price per category.

Details:

Table definition considered on oracle 10.x:

create table test (
    ID number,
    Category varchar (20),
    Keyword varchar (20),
    BidPrice number
);

Data:

insert into test values (1, 'Category-A', 'Keyword-A1', 110);
insert into test values (2, 'Category-A', 'Keyword-A2', 121);
insert into test values (3, 'Category-A', 'Keyword-A3', 130);
insert into test values (4, 'Category-A', 'Keyword-A4', 125);
insert into test values (5, 'Category-A', 'Keyword-A5', 115);
insert into test values (6, 'Category-A', 'Keyword-A6', 133);
insert into test values (7, 'Category-B', 'Keyword-B1', 105);
insert into test values (8, 'Category-B', 'Keyword-B2', 111);
insert into test values (9, 'Category-B', 'Keyword-B3', 108);
insert into test values (10, 'Category-B', 'Keyword-B4', 128);
insert into test values (11, 'Category-B', 'Keyword-B5', 144);
insert into test values (12, 'Category-B', 'Keyword-B6', 101);
insert into test values (13, 'Category-C', 'Keyword-C1', 150);
insert into test values (14, 'Category-C', 'Keyword-C2', 137);
insert into test values (15, 'Category-C', 'Keyword-C3', 126);
insert into test values (16, 'Category-C', 'Keyword-C4', 121);
insert into test values (17, 'Category-C', 'Keyword-C5', 112);
insert into test values (18, 'Category-C', 'Keyword-C6', 118);

Output expected:

KEYWORD         CATEGORY      BIDPRICE
--------------  ------------  ----------
Keyword-A6      Category-A    133
Keyword-A3      Category-A    130
Keyword-A4      Category-A    125
Keyword-A2      Category-A    121
Keyword-A5      Category-A    115
Keyword-B5      Category-B    144
Keyword-B4      Category-B    128
Keyword-B2      Category-B    111
Keyword-B3      Category-B    108
Keyword-B1      Category-B    105
Keyword-C1      Category-C    150
Keyword-C2      Category-C    137
Keyword-C3      Category-C    126
Keyword-C4      Category-C    121
Keyword-C6      Category-C    118 

Note: Answer has to be only in SQL without use of any Oracle or database specific function.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T21:50:00+00:00Added an answer on June 13, 2026 at 9:50 pm

    I made this query but it is leaving the 6th row if it is biggest. Can any one help on this?

    select a.keyword, a.category, a.bidprice
    from
      test a,
      (
        select b.id, b.category
        from test b
        where (select distinct(c.category) from test c where b.category=c.category) = b.category
      ) xx
    where a.id in (select ss.id from test ss where a.category=ss.category and rownum<=5)
    group by a.category, a.bidprice, a.keyword
    order by a.category, a.bidprice desc;
    

    Guys,

    I solved it, please consider this:

    select a.keyword, a.category, a.bidprice
    from
      test a,
      (
        select b.id, b.category
        from test b
        where (select distinct(c.category) from test c where b.category=c.category) = b.category
        order by b.bidprice desc
      ) xx
    where a.id in (
      select id
      from (select dd.id, dd.category from test dd order by dd.bidprice desc) ss
      where a.category=ss.category
        and rownum<=5
    )
    group by a.category, a.bidprice, a.keyword
    order by a.category, a.bidprice desc;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with the schema below. I need to fetch the last
edit: my table schema below is poorly normalized as suggested and I have revamped
Please have a look at the schema below: CREATE TABLE Person (id int not
I have the schema below CREATE TABLE `vocabulary` ( `vid` int(10) unsigned NOT NULL
I have a many-to-many relation with a linked table. See (simplified) schema below. Created
Hi, I have a table called msgsubjects with a schema shown below. Basically it
I have a products table with below schema (ProductID INT, ProductStartDate date, ProductExpDate date,
I have a student marks table with schema as given below: Student -------- SNO
I have two tables names book_list and book_category . Schema is like below: book_list
i have the table below <tr id=group_1>...</tr> <tr id=el>...</tr> <tr id=el>...<tr> <tr id=group_2></tr> <tr

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.