-2

我需要以下 MySQL 查询方面的帮助

我想在没有任何子查询的情况下重写我的查询 - 但我不知道如何..

它是一个视频租赁商店数据库;)

SELECT k.first_name, k.last_name, SUM(amount) AS profit 
FROM payment AS p 
JOIN (SELECT c.* FROM customer AS c 
 JOIN rental AS r ON c.customer_id = r.customer_id 
WHERE r.return_date IS NULL GROUP BY c.customer_id HAVING 
COUNT(*) > '1') AS k ON p.customer_id = k.customer_id 
GROUP BY k.customer_id 
HAVING SUM(amount) > 100 
ORDER BY profit DESC;

谢谢 :)

4

1 回答 1

0

这个:

 SELECT c.first_name, c.last_name, c.customer_id,SUM(amount) AS profit 
 FROM payment AS p 
    INNER JOIN (customer c
        INNER join rental r
        ON c.customer_id=r.customer_id)
    ON p.customer_id = c.customer_id
 GROUP BY c.customer_id,c.last_name,c.first_name
 HAVING SUM(amount) > 100 
 ORDER BY profit DESC;

使用 INNER JOIN 会将此查询限制为仅限已付款的客户。

于 2013-07-11T15:41:57.680 回答