gpt4 book ai didi

php - 如何在 Select 语句 laravel 5.1 中编写子查询?

转载 作者:行者123 更新时间:2023-11-29 21:19:59 25 4
gpt4 key购买 nike

如何在 Laravel 5.1 中编写此查询

SELECT 
(SELECT firstname FROM registration_details a INNER JOIN users b
ON a.id = b.registerid
WHERE c.patientid = b.id ) AS patient,
(SELECT firstname FROM registration_details a INNER JOIN users b
ON a.id = b.registerid
WHERE c.doctorid = b.id ) AS doctor,
c.`appoinmentdate`
FROM `appoinments` c

我尝试了这样的方法,但是我得到了 Undefined property: stdClass::$id 错误

 DB::table('appoinments')
->select(DB::raw(
"(SELECT firstname FROM registration_details INNER JOIN users ON registration_details.id = users.registerid WHERE appoinments.patientid = users.id) AS patient",
"(SELECT firstname FROM registration_details INNER JOIN users ON registration_details.id = users.registerid WHERE appoinments.doctorid = users.id) As doctor",
"appoinments.appoinmentdate",
"appoinments.id",
"(SELECT timings FROM appoinment_time WHERE appoinment_time.id = appoinments.appoinment_time) AS apptime ",
"(SELECT branchname FROM branches WHERE branches.id = appoinments.branchcode) AS branch"))
->get();

最佳答案

终于得到答案了。感谢所有为我努力的人。

$appoinment = DB::table('appoinments')->select(DB::raw("(SELECT firstname FROM registration_details INNER JOIN users ON registration_details.id = users.registerid WHERE appoinments.patientid = users.id) AS patientid"));
$appoinment = $appoinment->addSelect(DB::raw("(SELECT firstname FROM registration_details INNER JOIN users ON registration_details.id = users.registerid WHERE appoinments.doctorid = users.id) As doctorid"));
$appoinment = $appoinment->addSelect(DB::raw("appoinments.appoinmentdate"));
$appoinmentlist = $appoinment3->addSelect(DB::raw("appoinments.id"))->get();

关于php - 如何在 Select 语句 laravel 5.1 中编写子查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35765512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com