SQL Questions
SQL Questions
1. Get the profit of every movie with Rating greater than 8.0
2. Get all the movies having a Profit of at least 30 crores, and belong to "Action", "Animation"
or "Drama" genres.
3. Scale up the ratings from 5 to 100 in the movie table.
SQL FUNCTIONS
DATE FUCTION
CAST FUNCTION
7. Get all the collection_in_cr values from the movie table that's present in the database,
where the rating is greater than 8.5
8. Get all years from the movie table that's present in the database which belongs to the
Drama genre.
9. Get all the DISTINCT leap years from the movie table in the database. A year is considered
a leap year if it satisfies any one of the below conditions,
It is divisible by 400.
10. For each movie, get the ceil, floor, and round (to 1 decimal) values of the budget.
11. Get the average rating of movies released in the year 2010 and round to the 1 decimal
value.
12. Get all the collections of all movies in the database that are greater than 250.
13. Get all the movie names that are released in 2010 and belong to the "Action" genre.
CASE CLAUSE
rating category
<5 Poor
>7 Good
15. Get the number of movies with collection greater than or equal to 100 crores, and the
movies with collection less than 100 crores.
SET OPERATORS
16. Get all the movie ids in which actors Robert Downey Jr. (id=6) & Chris Evans(id=22) have
been casted
17. Get all the movie ids in which actor Robert Downey Jr. (id=6) is casted and not Chris
Evans(id=22)
18. Get all the unique movie ids in which either actor Robert Downey Jr. (id=6) or Chris
Evans(id=22) is casted
ORDER BY CLAUSE IN SET OPERATORS
19. Get all the movie ids in which actor Robert Downey Jr. (id=6) is casted & not Chris
Evans(id=22). Sort the ids in the descending order
20. Get the first 5 unique movie ids in which either actor Robert Downey Jr. (id=6) or Ryan
Reynolds(id=7) is casted. Sort ids in the descending order.
JOINS
NATURAL JOIN
21. Get the details of the instructor who is teaching "Cyber Security". (full_name, gender)
22. Get student full name and their scores in "Machine Learning" (course with id=11). (full_name, score)
INNER JOIN
23. Get the details of students who enrolled for "Machine Learning" (course with id=11).
(full_name, age, gender)
24. Get the reviews given by "Varun" (student with id = 1). (course_id, content, created_at).
LEFT JOIN
25. Get the course details that doesn't have any students. (course_name)
26. Get the instructors details who is not assigned for any course. (full_name, gender)
27. Fetch the name of the students who gave reviews to the "Machine Learning" course. (full_name)
28. Fetch the course names in which "Varun" has registered. (course_name)
29. Get all the courses taken by the student with id=1 and his respective scores in each course.
(course_name, score)
30. Get all the students who registered for at least one course. (full_name)
31. Get the course name and the average score for each course. (course_name, avg_score)
32. Get the number of students in each course . (course_name, no.of.students)
VIEWS
SUBQUERIES
35. Get the rating variance of products in the "MOBILE" category. Rating variance is the difference
between average rating and rating of a product. Rating variance is the difference between average
rating and rating of a product
36. Get all the products from the "MOBILE" category, where rating is greater than average rating.