gpt4 book ai didi

mysql - 如何通过mysql设置select in变量的输出?

转载 作者:行者123 更新时间:2023-11-29 10:49:33 24 4
gpt4 key购买 nike

我想计算设置为变量@x 的产品ID。在 phpmyadmin 查询中没有过程或函数。但错误

set @x=70489;
set @y = select count(`product_id`) from `oc_product` where `language_id`=2 and `product_id`=@x;

select @x;
SELECT @y;

SQL query: Documentation set @x=70489 set @y = select count(product_id) from oc_product where language_id=2 and product_id=@x; MySQL said: Documentation 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set @y = select count(product_id) from oc_product where `langua' at line 2

最佳答案

在选择的开始和结束处添加 ()。

set @x=70489;
set @y = (select COUNT(*) from `oc_product` where `language_id`=2 and `product_id`= @x);

SELECT @x;
SELECT @y;

关于mysql - 如何通过mysql设置select in变量的输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43981202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com