Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create lab4.sql #217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Create lab4.sql #217

wants to merge 2 commits into from

Conversation

JayEm65
Copy link

@JayEm65 JayEm65 commented Oct 5, 2024

No description provided.

Copy link

@Imran-imtiaz48 Imran-imtiaz48 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1. Store, Staff, and Payment Join Logic:

The first query performs a JOIN between the store, staff, and payment tables.

FROM 
    store s
JOIN 
    staff st ON s.store_id = st.store_id
JOIN 
    payment p ON st.staff_id = p.staff_id  -- Fixed join logic
GROUP BY 
    s.store_id;

Strengths:

  • The join logic between store, staff, and payment looks correct and straightforward.
  • Grouping by s.store_id is appropriate for aggregating data based on the store level.

Suggestions:

  • Column Selection: It would be helpful to know what specific columns are selected in this query. Consider adding SELECT s.store_id, COUNT(p.payment_id) or similar, to indicate the aggregated data.
  • Alias Consistency: Ensure aliases (s, st, p) are used consistently throughout the query to avoid ambiguity.
  • Potential Use of LEFT JOIN: If some stores or staff may not have corresponding payment data, you may want to consider using a LEFT JOIN for payment p to ensure all stores and staff are included, even without payment records.

2. Average Running Time of Films per Category:

This query computes the average running time of films for each category and rounds the result to two decimal places.

SELECT 
    c.name AS category_name,
    ROUND(AVG(f.length), 2) AS average_running_time  -- Rounded to two decimal places
FROM 
    category c
JOIN 
	@@ -110,4 +112,4 @@ FROM
LEFT JOIN 
    inventory i ON f.film_id = i.film_id
GROUP BY 
    f.film_id, f.title;

Strengths:

  • Rounding: The ROUND(AVG(f.length), 2) ensures that the average running time is displayed with two decimal places, which improves readability.
  • Joins: The use of LEFT JOIN on inventory ensures that films without inventory records are still considered, which is important if some films are not in stock.

Suggestions:

  • Query Continuity: There's a truncation or break (@@ -110,4 +112,4 @@) that suggests part of the query is missing. Ensure that the FROM and other necessary clauses are complete. The category table (category c) should likely be joined with the film_category and film tables to map films to their categories.
  • Correct GROUP BY: If you're calculating the average running time per category, the GROUP BY clause should likely group by the category name or ID, not by individual films. Example:
    GROUP BY 
        c.name;
  • Column Selection: Ensure that f.length (from the film table) is correctly referenced in the SELECT clause for the AVG function. Also, f.title should be removed from the GROUP BY as it is unnecessary for the desired aggregation (per category).

Example Refinement:

For the second query, here's an improved version based on the context of calculating the average running time for each category:

SELECT 
    c.name AS category_name,
    ROUND(AVG(f.length), 2) AS average_running_time
FROM 
    category c
JOIN 
    film_category fc ON c.category_id = fc.category_id
JOIN 
    film f ON fc.film_id = f.film_id
LEFT JOIN 
    inventory i ON f.film_id = i.film_id
GROUP BY 
    c.name;

This version joins category with film_category and film to ensure that the average length is calculated at the category level.

Imran-imtiaz48

This comment was marked as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants