0% found this document useful (0 votes)
9 views3 pages

SQL Questions

The document outlines various SQL queries and functions for querying movie and course data. It includes expressions for retrieving movie profits, ratings, and collections, as well as using date functions, cast functions, arithmetic, string functions, and joins. Additionally, it covers creating views and subqueries for analyzing product ratings in specific categories.

Uploaded by

akshaychintu876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

SQL Questions

The document outlines various SQL queries and functions for querying movie and course data. It includes expressions for retrieving movie profits, ratings, and collections, as well as using date functions, cast functions, arithmetic, string functions, and joins. Additionally, it covers creating views and subqueries for analyzing product ratings in specific categories.

Uploaded by

akshaychintu876
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPRESSIONS IN QUERYING

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

4. Get the number of action movies released in the year 2010.


5. Get all the names of the movies that are released in summer, i.e., between April and June.
6. Get the month in which the highest number of movies are released.

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 4 and not divisible by 100.

It is divisible by 400.

ARITHMETIC AND STRING FUUNCTIONS

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

14. Categorise movies as following

rating category

<5 Poor

5 >= _ <= 7 Average

>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

PAGINATION IN SET OPEARTORS

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)

QUERYING WITH JOINS

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)

USING JOINS IN OTHER CLAUSES

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)

USING JOINS WITH AGGREGATIONS

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

33. Create order_with_products view with order_id, product_id, no_of_units, name,


price_per_unit, rating, category, brand.
34. From the order_with_products view created above, get the name and no_of_units ordered in
order_id = 802.

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.

You might also like