Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 当存在多行时,如何将查询结果(行)存储在变量中_Mysql_Variables_Subquery - Fatal编程技术网

Mysql 当存在多行时,如何将查询结果(行)存储在变量中

Mysql 当存在多行时,如何将查询结果(行)存储在变量中,mysql,variables,subquery,Mysql,Variables,Subquery,我试图将查询结果存储到变量中。但我有以下错误 subquery returns more than 1 row 这是我使用的代码: set @var := (select country from (SELECT country FROM employeeTABLE order by rand() limit 250)t where country='USA'); 查询随机选择250个国家,然后返回随机选择的250个国家中的country=USA。我想把这些存储在变量中。 假设在随机选择的

我试图将查询结果存储到变量中。但我有以下错误

subquery returns more than 1 row
这是我使用的代码:

set @var := (select country from (SELECT country FROM employeeTABLE 
order by rand() limit 250)t where country='USA');
查询随机选择250个国家,然后返回随机选择的250个国家中的country=USA。我想把这些存储在变量中。 假设在随机选择的250个国家中有3个国家=美国。因此,我希望:

USA
USA
USA

您的查询没有意义,您可以将其写成
set@var:=“USA”
我需要所有这些。我的意思是查询的计数(*)也是需要的。然后在你的问题中适当地解释你想要什么以及你的问题是什么。或者你的意思是从国家为“美国”的雇员表中选择计数(*)吗?这可能对你有帮助。。。