我有两张桌子如下所示:
(1)记帐
mysql> select * from tblaffiliatesaccounts limit 12;
+----+-------------+-------+------------+
| id | affiliateid | relid | lastpaid |
+----+-------------+-------+------------+
| 1 | 2 | 444 | 2019-11-01 |
+----+-------------+-------+------------+affiliateid:附属机构id,relid:产品id lastpaid:最新付款日期
(2)待定
mysql> select * from tblaffiliatespending limit 12;
+----+----------+--------+--------------+
| id | affaccid | amount | clearingdate |
+----+----------+--------+--------------+
| 1 | 1 | 0.03 | 2019-12-01 |
+----+----------+--------+--------------+情感:这是tblaffiliatesaccounts的ID值
现在我知道了affiliateid=2,我想查询所有tblaffiliatespending行都满足它的affiliateid=2条件。
如何处理胶囊?和MySQL的通讯?我想知道两种比较的方法。
我只知道如何在一个表中查询。
胶囊是一个简单的包装包装的Laravel包装。
发布于 2019-11-01 11:02:31
我不知道你到底在挣扎什么,但我相信你需要这样的东西:
SELECT *
FROM tblaffiliatespending s
INNER JOIN tblaffiliatesaccounts a ON (a.id = s.affaccid AND a.affiliateid = 2);至于使用Capsule,我认为这应该是可行的:
Capsule\DB::table('tblaffiliatespending s')->select('*')->join('tblaffiliatesaccounts a', 'a.id', '=', 's.affaccid')->where("a.affiliateid", "2")->get();免责声明:我从未使用过胶囊,我指的是过时的文档。我不确定胶囊查询是否会起作用,但无论如何它都会起作用。如果有问题,请给我留言。另外,请记住,MySQL查询更好,并且在大多数情况下将工作得更快,因为条件在联接中。我不知道如何才能在胶囊中做到这一点,所以我选择了where子句。
如果你还有其他问题,请告诉我。
https://stackoverflow.com/questions/58657938
复制相似问题