为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 laravel 7 中编写自我加入作为我的 php sql 查询

如何在 laravel 7 中编写自我加入作为我的 php sql 查询

PHP
开满天机 2023-04-15 16:55:51
这是我的 php sql 代码如何在 laravel 7 中实现它......请任何人帮助我......$results = $mysqli->query("SELECT a.ID,a.nm,b.nm as under,IFNULL(a.openingbalance,'0') AS openingbalance,a.drcr,a.bankacno,                                             a.bankifsccode,a.address,a.workphone,a.mobile,a.email,a.contactperson FROM maccountgroup a,                                             maccountgroup b WHERE a.parent_id=b.ID AND a.GL='L' and a.ACTIVE='Y' AND b.natureid = 1 AND a.comp_code = '".$_SESSION['comp_code']."'");
查看完整描述

1 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

您应该看看join是如何工作的。您要做的是与同一张表进行连接。

还要看看join在 Laravel 上是如何工作的。所以对于您的查询,有不同的方法可以做到这一点,这里是一个例子:

DB::table('maccountgroup as a')
  ->join('maccountgroup as b', 'a.parent_id', 'b.ID')
  ->where('a.GL', 'L')
  ->where('b.ACTIVE', 'Y')
  ->where('b.natureid', 1)
  ->where('a.comp_code', $request->comp_code) 
  ->get();


查看完整回答
反对 回复 2023-04-15
  • 1 回答
  • 0 关注
  • 94 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信