i need followin mysql query
i want rewrite query without subqueries - dont know how..
it video rental store database ;)
select k.first_name, k.last_name, sum(amount) profit payment p join (select c.* customer c join rental r on c.customer_id = r.customer_id r.return_date null group c.customer_id having count(*) > '1') k on p.customer_id = k.customer_id group k.customer_id having sum(amount) > 100 order profit desc;
thanks :)
this this:
select c.first_name, c.last_name, c.customer_id,sum(amount) profit payment p inner join (customer c inner join rental r on c.customer_id=r.customer_id) on p.customer_id = c.customer_id group c.customer_id,c.last_name,c.first_name having sum(amount) > 100 order profit desc;
using inner join restrict query customers have made payments.
Comments
Post a Comment