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

  • SEARCH
  • Home
  • 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 4016046
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:41:33+00:00 2026-05-20T09:41:33+00:00

I have a database with 3 relations Offers, Products & Categories. I’m trying to

  • 0

I have a database with 3 relations Offers, Products & Categories. I’m trying to find the day of the month with the max number of offered products. I need to return the Category Name (CN), Day with the max number of offers (OD) and the number of offers (PC).

I have this query:

SELECT CN, MAX(PC)
FROM
(
SELECT c.nombre as CN, EXTRACT(DAY FROM o.fecha) as OD, count(o.id_producto_ofertado) AS PC
FROM ofertas o join (categorias c JOIN productos p ON c.id = p.categoria) on o.id_producto_ofertado = p.id
GROUP BY  EXTRACT(DAY FROM o.fecha), c.nombre
)
GROUP BY CN

I suppose it works. But the result is a relation with 2 cols: CN & MAX(PC). If I try to bring the day (OD), because I need it, by using:

SELECT CN, MAX(PC), OD
FROM
(
SELECT c.nombre as CN, EXTRACT(DAY FROM o.fecha) as OD, count(o.id_producto_ofertado) AS PC
FROM ofertas o join (categorias c JOIN productos p ON c.id = p.categoria) on o.id_producto_ofertado = p.id
GROUP BY  EXTRACT(DAY FROM o.fecha), c.nombre
)
GROUP BY CN, OD

Then it return a 3 cols relation: CN, MAX(PC) & OD. BUT with the Category Name (CN) repeated, I think that because I need to group by OD in order to extract also the day. So, the return contains a row for each of the 31 days.

I just need a row for each category name, returning the category name, the number of the day of the month with the greatest number of offers and the greatest number of offers.

I’m stuck right now, cause I don’t know what to do. Thanks

  • 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-05-20T09:41:34+00:00Added an answer on May 20, 2026 at 9:41 am

    You could use row_number to select the row with the highest offer count:

    select  CustomerName
    ,       OrderDate
    ,       OfferCount
    from    (
            select  CustomerName
            ,       OrderDate
            ,       OfferCount
            ,       row_number() over (partition by CustomerName
                                       order by OfferCount desc) as rn
            from    (
                    select  c.nombre as CustomerName
                    ,       EXTRACT(DAY FROM o.fecha) as OrderDate
                    ,       count(o.id_producto_ofertado) as OfferCount
                    FROM    ofertas o 
                    join    categorias c 
                    on      o.id_producto_ofertado = p.id
                    join    productos p 
                    on      c.id = p.categoria
                    group by
                            c.nombre
                    ,       EXTRACT(DAY FROM o.fecha)
                    ) as GroupByDay
            ) as WithRowNumber
    where   rn = 1
    

    The subquery for row_number might not be necessary, but I haven’t got a test Oracle nearby.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it might sound stupid. can we have a database containing some tables without relations.
I'm building a StackOverflow mini-clone. I have the following database relations: questions - question_id
I have a Database that has the following relations: Transaction->Purchase->Item->Schedule Transaction - self explanitory
i have in the database typical tables like user, usergroup, and they have relations.
I am trying to design a database structure for a website that offers people
I'm following the Stanford Database course and there's a question where we have Find
I am trying to update an whole entity object with relations in database in
I have the following code (Database is SQL Server Compact 4.0): Dim competitor=context.Competitors.Find(id) When
I have a database with some relations. I have two tables in this example:
I have a question about Criteria method, one-to-many relation to the database, 'one' is

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.