使用此查询,我收到第一个报告ID,但我想检索最新的服务报告ID。
提前致谢。
CustomerRequest::where('escalated', '=', 0)
->whereIn('customer_request.complain_status_id', array(9, 10))
->leftjoin('service_report_mapping', 'service_report_mapping.complain_id', '=', 'customer_request.id')
->select('service_report_mapping.report_id')
->orderBy('service_report_mapping.report_date', 'DESC')
->groupBy('customer_request.id')
->get();
输出: service_report_id : 20903
服务报告ID:20903 47185 87609 98661 98662
98662是我最新的报告ID。
答案 0 :(得分:0)
检查一下:
CustomerRequest::where('escalated', '=', 0)
->whereIn('customer_request.complain_status_id', array(9, 10))
->leftjoin('service_report_mapping', 'service_report_mapping.complain_id', '=', 'customer_request.id')
->select('service_report_mapping.report_id')
->orderBy('service_report_mapping.id', 'DESC')
->groupBy('customer_request.id')
->get();
答案 1 :(得分:0)
答案 2 :(得分:0)
你应该试试这个:
只需将orderBy
放在groupBy
之后,然后检查:
CustomerRequest::where('escalated', '=', 0)
->whereIn('customer_request.complain_status_id', array(9, 10))
->leftjoin('service_report_mapping', 'service_report_mapping.complain_id', '=', 'customer_request.id')
->select('service_report_mapping.report_id')
->groupBy('customer_request.id')
->orderBy('service_report_mapping.report_date', 'DESC')
->get();
或强>
CustomerRequest::where('escalated', '=', 0)
->whereIn('customer_request.complain_status_id', array(9, 10))
->leftjoin('service_report_mapping', 'service_report_mapping.complain_id', '=', 'customer_request.id')
->select('service_report_mapping.report_id')
->groupBy('customer_request.id')
->orderBy('service_report_mapping.id', 'DESC')
->get();
答案 3 :(得分:0)
给出的信息不多......
你试过吗
CustomerRequest::where('escalated', '=', 0)
->whereIn('customer_request.complain_status_id', array(9, 10))
->leftjoin('service_report_mapping', 'service_report_mapping.complain_id', '=', 'customer_request.id')
->select('service_report_mapping.report_id')
->latest();
?
你的小组背后的最初想法是什么?顺便说一下?似乎没必要吗?
答案 4 :(得分:0)
我得到了解决方案。使用max()
我将收到上次报告ID。
感谢大家的回答。
CustomerRequest::where('escalated', '=', 0)
->whereIn('customer_request.complain_status_id', array(9, 10))
->leftjoin('service_report_mapping', 'service_report_mapping.complain_id', '=', 'customer_request.id')
->select('max(service_report_mapping.report_id)')
->orderBy('service_report_mapping.report_date', 'DESC')
->groupBy('customer_request.id')
->get();