良い日! Laravelの新作です。私はそれをするために多くの方法を試みたが、それでも私にエラーを与える。私は雄弁未処理クエリからのlaravelクエリビルダ
Select t.employee_code,
CASE WHEN t.day = '2017-08-19' THEN t.PRESENT ELSE NULL END AS `2017-08-19`,
CASE WHEN t.day = '2017-08-20' THEN t.PRESENT ELSE NULL END AS `2017-08-20`,
CASE WHEN t.day = '2017-08-21' THEN t.PRESENT ELSE NULL END AS `2017-08-21`,
CASE WHEN t.day = '2017-08-22' THEN t.PRESENT ELSE NULL END AS `2017-08-22`,
CASE WHEN t.day = '2017-08-23' THEN t.PRESENT ELSE NULL END AS `2017-08-23`,
CASE WHEN t.day = '2017-08-24' THEN t.PRESENT ELSE NULL END AS `2017-08-24`
FROM (
select e.employee_code,
Cast(e_l.time_in As date) As Day,
Case
WHEN e_l.time_in IS NULL THEN 'A'
WHEN DAYOFWEEK(e_l.time_in) In(7, 1) Then 'W'
ELSE 'P'
end as PRESENT
from employee As e
left join employees_logs As e_l on e.id = e_l.employee_id)
AS t
には、このSQLクエリを変換しようとしていると私は、この雄弁な方法
public static function statusReport($data){
$start_date = $data['start_date'];
$end_date = $data['end_date'];
$date_array = self::getDatesFromRange($start_date, $end_date);
$query = DB::raw("(Select t.employee_code,
CASE WHEN t.day = '$start_date' THEN t.Present ELSE NULL END AS '$start_date')");
$query->addSelect(
DB::raw("(
SELECT employee.id as emp_id,
CONCAT(employee.firstname, " ",employee.lastname) AS employee_name,
CAST(employees_log.time_in as date) as date_given,
CASE WHEN employee_logs.time_in IS NULL THEN 'A'
WHEN leave.status_id = 4 AND leave_request.with_pay = 1 THEN 'L'
WHEN leave.status_id = 4 AND leave_request.with_pay = 0 THEN 'LOP'
WHEN DAYOFWEEK(employee_logs.time) In(7, 1) THEN 1 AS 'W'
ELSE 'P' END as status
LEFT JOIN employee_logs On employee.id = employees_logs.employee_id
JOIN leave On employee.id = leave.emp_id
JOIN leave_request On leave.id = leave_request.leave_id
WHERE employee_logs.time_in BETWEEN '$start_date' AND '$end_date') As `t`"));
$data = $query->get();
return $data;
}期待される出力は、このクエリは
あるを試してみました毎日の従業員のステータスを通知します。たとえば、この日が週末の場合、出力に「W」が表示されます。従業員が「A」を欠席していて、存在する場合は「P」です。誰かが私にこれを手伝ってくれることを願っているまず事前に感謝
、それをあなたの質問を追加します。 –
C:\ xampp \ htdocs \ hrpayroll \ api \ app \ Http \ Models \ AttendanceReportModel.phpの文法エラーが予期せぬ「行」178 –
なぜ2つの 'DB :: raw'ステートメントがありますか、 –