Professional Documents
Culture Documents
Dapancuoiky
Dapancuoiky
film_id ) as total
FROM staff as s
join rental as r on r.staff_id = s.staff_id
JOIN inventory as i ON r.inventory_id = i.inventory_id
where year(r.rental_date) = 2005
GROUP BY s.staff_id;
DELIMITER //
CREATE FUNCTION totalPayByCustomer(c_id INT)
RETURNS decimal(10,2)
READS SQL DATA
BEGIN
DECLARE t INT;
select sum(p.amount) into t
from customer as c
join payment as p on p.customer_id = c.customer_id
where c.customer_id = c_id;
RETURN t;
END
//
DELIMITER ;
elseif (temp > 50) then insert into customer_rank values (new.customer_id,
'Silver');
end if;
ELSE
if (temp > 150) then update customer_rank set rank = 'Platinum' where
customer_id = new.customer_id;
elseif (temp > 100) then update customer_rank set rank = 'Gold' where
customer_id = new.customer_id;
end if;
END IF;
END
//
DELIMITER ;
2 1 3 4