如何将其置于与设定值一起使用的功能中,例如函数xy(@ q,@ p)
SET @q='10';
SET @p='5';
SELECT @a_rows := COUNT(*) FROM 'main1' WHERE status='0' && price<= @p && quantity > '0';
IF @a_rows = '0' THEN
INSERT INTO detail1 (quantity,price,status) VALUES (@q,@p,'0');
INSERT INTO detail2 (quantity,price,status) VALUES (@q,@p,'0');
ELSEIF @a_rows='1' THEN
INSERT INTO detail3 (quantity,price,status) VALUES (@q,@p,'0');
ELSE
;
ENDIF
答案 0 :(得分:0)
做我在之前的评论中说的话...只是使用一个案例。像这样。
注意:你不能只运行一堆插件,你必须分别为每个插件添加...
SET @q='10';
SET @p='5';
SELECT @a_rows := COUNT(*) FROM 'main1' WHERE status='0' && price<= @p && quantity > '0';
INSERT INTO detail1 (quantity,price,status)
values
(
(CASE @a_rows WHEN 0 THEN @q ELSE NULL END),
(CASE @a_rows WHEN 0 THEN @p ELSE NULL END),
(CASE @a_rows WHEN 0 THEN 0 ELSE NULL END)
);
INSERT INTO detail2 (quantity,price,status)
values
(
(CASE @a_rows WHEN 0 THEN @q ELSE NULL END),
(CASE @a_rows WHEN 0 THEN @p ELSE NULL END),
(CASE @a_rows WHEN 0 THEN 0 ELSE NULL END)
);
INSERT INTO detail3 (quantity,price,status)
values
(
(CASE @a_rows WHEN 1 THEN @q ELSE NULL END),
(CASE @a_rows WHEN 1 THEN @p ELSE NULL END),
(CASE @a_rows WHEN 1 THEN 0 ELSE NULL END)
);
答案 1 :(得分:-1)
你可以试试这个
CASE @a_rows
WHEN 0 THEN
INSERT INTO detail1 (quantity,price,status) VALUES (@q,@p,'0');
INSERT INTO detail2 (quantity,price,status) VALUES (@q,@p,'0');
WHEN 1 THEN
INSERT INTO detail3 (quantity,price,status) VALUES (@q,@p,'0');
ELSE
#If neither 0 or 1
END CASE;