gpt4 book ai didi

mysql - Laravel DB 查询组按输出不同

转载 作者:行者123 更新时间:2023-11-29 18:39:39 27 4
gpt4 key购买 nike

我在 Laravel 项目中实现了以下查询,如果我在控制台中复制粘贴,则该查询正在工作,但数据库对象在子查询 group by zeit_von 上设置为 group by zeit_von为空

$data = DB::table('e_supply AS s')
->select(
DB::raw('count(s.employee) as anzahl_employee'),
DB::raw('group_concat(a.account_lastname order by a.account_lastname ) AS employee_names'),
DB::raw('date_format(s.zeit_von, "%Y") as y'),
DB::raw('date_format(s.zeit_von, "%m") as m'),
DB::raw('date_format(s.zeit_von, "%d") as d'),
DB::raw('date_format(s.zeit_von, "%h") as h')
)
->leftJoin('phpgw_accounts AS a', 'a.account_id', '=', 's.employee')
->where('deleted', 0)
->whereIn('supply_status', [1,3])
->where(
DB::raw('( select count(cal_id) from phpgw_cal_utf8 as c
where c.owner=s.employee
and deleted=0
and date_format(s.zeit_von, "%d.%m.%y")=date_format(from_unixtime(c.mdatetime), "%d.%m.%y")
and c.category="Krank"
)<1 and date_format((s.zeit_von), "%Y")="'.$year.'" group by zeit_von'
)
)
->get();

在这种情况下我缺少什么?

最佳答案

使用 whereRaw 进行子查询抑制了我遇到的问题

$data = DB::table('e_supply AS s')
->select(
'zeit_von as raw_time',
DB::raw('count(distinct s.employee) as anzahl_employee'),
DB::raw('group_concat(a.account_lastname order by a.account_lastname ) AS employee_names'),
DB::raw('date_format(s.zeit_von, "%Y") as y'), DB::raw('date_format(s.zeit_von, "%m") as m'),
DB::raw('date_format(s.zeit_von, "%d") as d'), DB::raw('date_format(s.zeit_von, "%h") as h')
)
->leftJoin('phpgw_accounts AS a', 'a.account_id', '=', 's.employee')
->where('deleted', 0)
->whereIn('supply_status', [1, 3])
->whereRaw(
DB::raw('( select count(cal_id) from phpgw_cal_utf8 as c
where c.owner=s.employee
and deleted=0
and date_format(s.zeit_von, "%d.%m.%y")=date_format(from_unixtime(c.mdatetime), "%d.%m.%y")
and c.category="Krank"
)<1'
)
)
->whereYear('s.zeit_von', $year)
->groupBy('zeit_von')
->get();

关于mysql - Laravel DB 查询组按输出不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45033402/

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