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

Querying Movies with Ratings 7-9

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)
189 views3 pages

Querying Movies with Ratings 7-9

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

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, [Link])
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.

Common questions

Powered by AI

SQL set operators like UNION, INTERSECT, and EXCEPT can be used to manage movie data by distinguishing movie IDs where actors are cast. For instance, using EXCEPT, you could find movies with Robert Downey Jr. but not Chris Evans, while UNION helps in fetching unique IDs involving either actor . Set operations enable complex queries that align with specific casting requirements, enhancing data differentiation .

SQL view creation simplifies complex queries by allowing reusable query results, enhancing management and efficiency. Creating views like 'order_with_products' consolidates multiple data points into a single access point, reducing query complexity . This strategy not only standardizes data retrieval processes but also optimizes performance, as pre-defined views can save computation time and resources when repeatedly accessing common data sets.

Pagination is crucial for handling large datasets by breaking down data into manageable pages, enhancing performance and user experience. In SQL, pagination can be applied using LIMIT and OFFSET clauses, as shown in queries retrieving movie IDs, allowing only the top results, or for specific ranges . This technique ensures efficient data handling and display in applications dealing with extensive datasets.

CASE clauses categorize data by providing conditional logic within SQL queries, enabling classification frameworks. For movie ratings, a CASE clause can systematically classify ratings into 'Poor', 'Average', and 'Good' categories based on predefined criteria, enhancing readability and analysis of rating trends . This function enables dynamic categorization without altering the underlying data structure.

Subquery techniques expand SQL capabilities by allowing nested queries to refine data analysis. They help calculate complex statistics, like rating variance in the "MOBILE" category, determining deviations from average ratings through nested queries . Such techniques provide deeper analytical insights by enabling multi-layered data interrogation, crucial for detailed market analyses and manufacturing improvements.

To maintain data uniqueness and manage actor-based associations, SQL uses DISTINCT clauses and set operations. Queries can ensure unique movie ID retrieval involving actors by employing DISTINCT, while managing specific actor combinations through UNION or EXCEPT helps isolate individual contributions within the database . These strategies ensure integrity and precise actor-performance management in large datasets, facilitating cleaner data associations.

SQL functions like DATE FUNCTIONS, CAST FUNCTION, arithmetic, and string functions enhance querying by allowing complex data manipulation and extraction. For example, to find movies released in summer, SQL date functions can be used to filter dates between April and June . Such functions also allow transformation and scaling of data, as seen in queries that adjust ratings or calculate statistical figures like average ratings .

Arithmetic and string functions significantly enhance data analysis and presentation by allowing nuanced data transformations. For instance, using functions like CEIL, FLOOR, and ROUND on movie budgets provides precise budget rounding, beneficial for financial reporting . Similarly, scaling ratings from 5 to 100 offers a clearer understanding of movie evaluations, improving comparative analysis and presentation of statistical data .

SQL joins like INNER JOIN, LEFT JOIN, and NATURAL JOIN allow extraction of different relational data aspects. INNER JOIN enables fetching detailed student enrollment data for specific courses . LEFT JOIN helps identify courses without students by showing data entries where no matching records exist in the student table . These join types provide tailored views of data relationships, facilitating comprehensive information retrieval from complex databases.

The CAST function is used to convert a variable from one data type to another, which is essential when dealing with conditions requiring precise data types. For instance, when retrieving collection values for movies with ratings greater than 8.5, CAST can ensure correct data type conversions for accurate comparisons and data retrieval .

You might also like