雄辩:获取多于一行的列值(x)存在的所有行(SQL DB)

问题描述 投票:0回答:1

我想在Laravel的Eloquent中执行以下原始SQL查询:

SELECT distinct user_id FROM order_payment WHERE user_id IN (SELECT user_id FROM order_payment where payment_status = 'paid' GROUP BY user_id HAVING COUNT(*) > 1);

[这里我将where in与属性user_id一起使用,以便选择同一表(order_payment)中具有payment_status=paid并按具有user_id的属性count > 1分组的所有行,然后最终选择[ C0]来自给定的用户ID集。

此查询的总体目标是获取所需列值(distinct user_ids)> 1 ...]的所有行。

例如:

user_id's in this case

上面的原始查询对我有用,但是现在我正在编写一个api,我想知道如何在Eloquent中复制它。

请帮助!

<<

所以可以使用we have 3 rows > A, B, C row A has user_id = 1; row B has user_id = 1; row C has user_id = 2; result should have [user_id: 1] as the count becomes greater than 1 groupBy方法完成这种查询的雄辩方式

php eloquent laravel-5.6 eloquent--relationship
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.