-- name: query_ce26d02e :execrows

    SELECT
        customer_id,
        first_name,
        last_name,
        email,
        address_id,
        store_id,
        activebool,
        create_date,
        last_update
    FROM
        customer
    WHERE
        customer_id = @customer_id;
;
-- name: query_8347248a :execrows

    SELECT
        film_id,
        title,
        description,
        release_year,
        rental_rate
    FROM
        film
    WHERE
        title LIKE '%' || @film_title || '%';
;
-- name: query_53d1b476 :execrows

    SELECT
        r.rental_id,
        r.rental_date,
        f.title AS film_title,
        r.return_date
    FROM
        rental AS r
    JOIN
        inventory AS i ON r.inventory_id = i.inventory_id
    JOIN
        film AS f ON i.film_id = f.film_id
    WHERE
        r.customer_id = @customer_id
    ORDER BY
        r.rental_date DESC;
;
-- name: query_326d1432 :execrows

    SELECT
        customer_id,
        COUNT(*) AS rental_count
    FROM
        rental
    GROUP BY
        customer_id
    HAVING
        customer_id = @customer_id
;
-- name: query_98490302 :execrows

    WITH CategoryRevenue AS (
        SELECT
            c.name AS category_name,
            SUM(p.amount) AS total_revenue
        FROM
            category AS c
        JOIN
            film_category AS fc ON c.category_id = fc.category_id
        JOIN
            film AS f ON fc.film_id = f.film_id
        JOIN
            inventory AS i ON f.film_id = i.film_id
        JOIN
            rental AS r ON i.inventory_id = r.inventory_id
        JOIN
            payment AS p ON r.rental_id = p.rental_id
        GROUP BY
            c.name
    )
    SELECT
        category_name,
        total_revenue
    FROM
        CategoryRevenue
    ORDER BY
        total_revenue DESC
    LIMIT 5
;
