0

是否可以在 Eloquent 中执行类似的操作?

SELECT (SELECT `name` from `players` WHERE `player_id`=`id`) AS `name`, `value` FROM `player_skills` WHERE `skillid`=0
4

2 回答 2

0

这看起来只是一个简单的关系,所以你可以这样做:

PlayerSkill::with('Player')->where('skillid',0)->get();
于 2013-08-16T13:26:31.960 回答
0

您可以像这样简单地运行您的查询

DB::raw('SELECT (SELECT `name` from `players` WHERE `player_id`=`id`) AS `name`, `value` FROM `player_skills` WHERE `skillid`=0');

或者

DB::statement('SELECT (SELECT `name` from `players` WHERE `player_id`=`id`) AS `name`, `value` FROM `player_skills` WHERE `skillid`=0');

或者

DB::select('SELECT (SELECT `name` from `players` WHERE `player_id` = ?) AS `name`, `value` FROM `player_skills` WHERE `skillid`= ?', array('id', 0));

祝你好运:)

于 2013-08-17T07:29:29.450 回答