列重命名方式属于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(",")});