[英]MySQL Control Flow Advice (CASE/THEN)
I have a very peculiar problem on my hands. 我手上有一个非常特殊的问题。 I have a project where the previous db engineer didn't gave a thought on db design and now im stuck with it. 我有一个项目,以前的数据库工程师没有对数据库设计产生任何想法,现在却陷入其中。 My question is simple: 我的问题很简单:
I have two different select queries and one of them should be executed if a field is set or not, ie 我有两个不同的选择查询,如果没有设置字段,则应执行其中一个查询,即
if field1 is 0 -> execute query 1 if field1 is 1 -> execute query 2 如果field1为0->执行查询1如果field1为1->执行查询2
So far i got here: 到目前为止,我到了这里:
SELECT should_i_care
FROM
product_sample
WHERE
pid='XXX'
CASE should_i_care
WHEN '1' then call query2
WHEN '0' then call query1
But found out that i cant declare the queries i want to run. 但发现我无法声明要运行的查询。 Any suggestions? 有什么建议么?
It should be a script or stored procedure like this 应该是这样的脚本或存储过程
DECLARE shouldICare INT;
SELECT @shouldICare := should_i_care
FROM
product_sample
WHERE
pid='XXX';
IF @shouldICare = 1 THEN
Call query2;
ELSE
Call query1;
END IF;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.