Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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_Ruby On Rails - Fatal编程技术网

列重命名方式属于mysql查询中的签入

列重命名方式属于mysql查询中的签入,mysql,ruby-on-rails,Mysql,Ruby On Rails,我想写一个类似这样的查询,分别查找硕士和博士研究生的奖学金: select sum(fellowship) as if(ID BELONGS TO #{ms_ids},'ms_fellowship','phd_fellowship') from fellowships where id in #{all_ids}; 在上面的查询中,我已经使用从另一个表中获得的ruby代码构建了两个数组student_ID和teacher_ID。但问题是,我不知道如何编写代码中要检查id是否属于某个数组的部分

我想写一个类似这样的查询,分别查找硕士和博士研究生的奖学金:

select sum(fellowship) as if(ID BELONGS TO #{ms_ids},'ms_fellowship','phd_fellowship') 
from fellowships where id in #{all_ids};

在上面的查询中,我已经使用从另一个表中获得的ruby代码构建了两个数组student_ID和teacher_ID。但问题是,我不知道如何编写代码中要检查id是否属于某个数组的部分(如上面的student_ids数组)

加入ID数组,假设它是一个类似于
[3,53,43,43]
的数组:

# >>>> #{all_ids.join(",")}

select sum(fellowship) as if(ID BELONGS TO #{ms_ids},'ms_fellowship','phd_fellowship') from fellowships where id in (#{all_ids.join(",")});