繁体   English   中英

MySQL的存储过程,如果(选择...)>变量然后

[英]Mysql stored procedure if (select…) > variable then

我想做类似的事情:

if ((select count(id) from abc where ...) > variableINT) then .....

为什么这不能正常工作?

在存储过程中执行以下操作(我假设您具有声明变量和编写查询的基本知识):

声明一个变量count_id: count_id NUMBER;

然后运行您的查询: select count(id) into count_id from abc where ...

然后可以测试该变量: if (count_id > ...) then .... end if

假设您有一个链接表(mylinks),其中包含从source_id到target_id的链接,而您只想查找具有5个以上链接的目标。 这将在MySQL中工作。 虽然不确定MS-SQL。

从mylinks组选择num_links> 5的target_id,count(source_id)作为num_links;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM