我需要帮助!我试着寻找答案但没有找到任何答案。
我正在使用MYSQL6。
功能:
DELIMITER $$
CREATE FUNCTION `get_total_customers`() RETURNS int(11)
BEGIN
DECLARE TotalCustomers INT;
SELECT (count(customer_id)*0.2) INTO TotalCustomers FROM customer;
RETURN TotalCustomers;
END
VIEW1:
CREATE VIEW PreferredStatus AS
SELECT customer_id, SUM(amount) AS TotalAmount, get_total_customers() AS Total FROM payment
GROUP BY customer_id
ORDER BY TotalAmount DESC;
视图2:
CREATE VIEW RegularStatus AS
SELECT customer_id, SUM(amount) AS TotalAmount, get_total_customers() AS Total FROM payment
GROUP BY customer_id
ORDER BY TotalAmount ASC
LIMIT Total;
这是使用视图的过程。
> DELIMITER $$
CREATE PROCEDURE `CustomerStatus`(in custID int, out status varchar(200))
BEGIN
declare number1 int;
declare totalvar int;
declare limit2 int;
IF custID in (SELECT customer_id FROM PreferredStatus) THEN
set status = "preferred";
ELSEIF custID in (SELECT customer_id FROM RegularStatus) THEN
set status = "casual";
ELSE
set status = "regular";
End If;
END
请帮忙!
-Thanks。
答案 0 :(得分:0)
您可以将LIMIT
添加到创建SELECT
的{{1}}:
VIEW
来自the docs的警告:
如果视图定义包含LIMIT子句,则从中选择 查看使用具有自己的LIMIT子句的语句,它是未定义的 适用的限制。