Group by Task
Group by Task
Group by Task
---tables
CREATE TABLE Actor(Actor_ID int,Actor_name varchar(30),Gender
varchar(10),debut_year int);
insert into actor values(1,'Aamir Khan','male',1988);
insert into actor values(2,'Shahrukh Khan','male',1992);
insert into actor values(3,'Kareena Kapoor','female',2000);
insert into actor values(4,'Kajol','female',1992);
insert into actor values(5,'Anushka Sharma','female',2008);
insert into actor values(6,'Ranbir Kapoor','male',2007);
insert into actor values(7,'Alia Bhatt','female',2012);
insert into actor values(8,'Ranveer Singh','male',2010);
insert into actor values(9,'Deepika Padukone','female',2006);
insert into actor values(10,'Shahid Kapoor','male',2003);
insert into actor values(11,'Katrina Kaif','female',2003);
insert into actor values(12,'Varun Dhawan','male',2012);
SELECT Genre,
MIN(release_year) AS OldestReleaseDate
FROM Movie
GROUP BY
Genre;
-----Calculate the total box office collection for movies of each genre.
-----Q5. Display the name of director, current count of movies and total count of
movies directed by him/her.
----- Display the name of lead_1 actors, their count of movies and their total DVD
sales.
SELECT
release_year,COUNT(*) AS num_movies
FROM
Movie
GROUP BY
release_year
HAVING
COUNT(*) > 1;
SELECT
genre,
COUNT(*) AS genre_count
FROM
Movie
GROUP BY
genre
ORDER BY
genre_count DESC;
SELECT
M.Movie_name,
D.Director_name
FROM
Movie M
JOIN
Director D ON M.director_id = D.Director_ID
ORDER BY
D.Director_name,
M.Movie_name;