我是Laravel新手。 在下面,我提到了我的代码如何在laravel查询生成器中实现此功能。
使用的表格是ab,cd,ef,gh,ij
SELECT ab.* FROM ab
WHERE ab.id IN (
SELECT ab_id FROM cd
WHERE ef_id = 1 AND status = 1
AND deleted_at IS NULL
AND ab_id IN (
SELECT ab_id FROM gh
WHERE ij_id IN (
SELECT id FROM ij
WHERE ef_id = 1 AND deleted_at IS NULL
) AND deleted_at IS NULL
) AND ab_id IN (
SELECT id FROM ab
WHERE deleted_at IS NULL AND usertest != 1
)
)AND ab.deleted_at IS NULL
GROUP BY ab.id
ORDER BY ab.created_at DESC;
答案 0 :(得分:0)
您可以将闭包传递给where条件并查询另一个表。
来自Laravel docs:
DB::table('users')
->whereExists(function ($query) {
$query->select(DB::raw(1))
->from('orders')
->whereRaw('orders.user_id = users.id');
})
->get();