Kind of movie more rented by the customer.

Hello

I need a list with the name of the customer and more rented film genre.

Database schema:
genres (id_genre, name)
movies (id_movie, id_genre, title)
DVD (id_dvd, id_movie)
customers (customer_id, name)
rents (customer_id, id_dvd, id_rent, date)

I need something like:
John, Action
Paul, Action
Mary, adventure
Christine, drama
Horror of Daniel
Victoria, Romance
Neal, Romance

Thank you!

Hello

Welcome to the forum!

1009991 wrote:
Hello

I need a list with the name of the customer and more rented film genre.

Database schema:
genres (id_genre, name)
movies (id_movie, id_genre, title)
DVD (id_dvd, id_movie)
customers (customer_id, name)
rents (customer_id, id_dvd, id_rent, date)

I need something like:
John, Action
Paul, Action
Mary, adventure
Christine, drama
Horror of Daniel
Victoria, Romance
Neal, Romance

Thank you!

The STATS_MODE aggregate function is the easiest way to do it.
Since I did not test versions of your tables, I will use the table scott.emp to illustrate:

SELECT       deptno
,       stats_mode (JOB)     AS top_job
FROM       scott.emp
GROUP BY  deptno
ORDER BY  deptno
;

Output:

`   DEPTNO TOP_JOB
---------- ---------
        10 CLERK
        20 ANALYST
        30 SALESMAN

If there is a tie for the most common value, STATS_MODE takes one of the values arbitrarily. For example, deptno = 20, there are 2 analysts and 2 clerks, but there is no way to see than just using STATS_MODE. If you want to view all the contenders for the most common value, and then use a Top - N query, with an analytical function as GRADE:

WITH     got_rnk          AS
(
     SELECT    deptno, job
     ,       RANK () OVER ( PARTITION BY  deptno
                                   ORDER BY      COUNT (*)     DESC
                      )   AS rnk
     FROM      scott.emp
     GROUP BY  deptno, job
)
SELECT       deptno, job
FROM       got_rnk
WHERE       rnk     = 1
ORDER BY  deptno, job
;

Output:

`   DEPTNO JOB
---------- ---------
        10 CLERK
        10 MANAGER
        10 PRESIDENT
        20 ANALYST
        20 CLERK
        30 SALESMAN

I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish the results you want from these data (if it is different from what you posted in your first post).
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).

See the FAQ forum {message identifier: = 9360002}

Tags: Database

Similar Questions

Maybe you are looking for

  • How can I report a possible fraud attempt?

    I got a call from so-called Tech Dept for Windows operating system.  They said that 72.2% of my system was already damaged.  They wanted me to buy security software at the price of 1 year, 2 years or life.  I told them I want to come back with them. 

  • Unable to connect to the virtual disk Service, Virtual Disk Manager Interface not registered

    I installed Windows 7 Ultimate on this laptop as a new installation about six months ago.  Since then, I don't think I ever ran diskmgmt.  Today, I joined a new external hard drive usb, it reported the drivers installed fine, but then the installatio

  • Downgrade 14.4 to 14.3 TMS

    Hi all As stated in my previous post, Cisco seem to have withdrawn in favour of TMS upgrade VCS to 14.4, we have a whole bunch of them, whereas makes life very difficult and frustrating. I've recently upgraded to TMS from 14.2 to 14.4 to relieve anot

  • EX90 - copy favorites between units

    Hello I have several EX90s and would like to copy the Favorites between several units. Anyone know where favorites are stored? they aren't xconf, currently logged in as root, and looking for a text or xml file. Thank you

  • Transfer of account Adobe Cloud and applications from PC to Mac

    Just buy a new Mac Mini and have a current of creative cloud and apps on a Windows-based PC. I would like to transfer creative Cloud and all apps, licenses to new Mac.How can I do this?Thank you!