我有3个表用户,项目,部门。我想从项目表中获取'owner_id'(DCE005)并从users表中获取user_id(2)并获取项目所有者的PM_dceid(DCE003)并检查( DCE003)不在department表的'dept_head'列中。如果(DCE003)不在dept_head(DCE004,DCE007,DCE009)中,那么从users表中获取值(3)。是否可以获得递归数据
foo
答案 0 :(得分:0)
会是这样的:
DB::select(DB::raw('select * from users, IF((SELECT users.PM_dceid FROM project, users WHERE project.owner_id = users.dceid AND project.owner_id= (SELECT owner_id FROM project LIMIT 1)) NOT IN (SELECT dept_head FROM Department)) WHERE id = " '.$yorKey.'" '));