我有一個原始查詢,當我在 phpMyAdmin 中運行此查詢時,它返回 3 個結果,但是當我嘗試使用 Laravel 查詢生成器時,我得到一個空數組。我的查詢SELECT id, reply_text, sending_timeFROM sms_sender_inbox_repliesWHERE phone_numberIN ('+1234567819', '+19873216154', '+15984989898')AND id IN ( SELECT MAX( id ) FROM sms_sender_inbox_replies GROUP BY phone_number)結果:+----+-----------------+---------------------+| id | reply_text | sending_time |+----+-----------------+---------------------+| 87 | This is a test | 2019-07-30 08:25:26 || 54 | And another one | 2019-07-29 06:35:11 || 12 | Last test | 2019-06-16 09:44:26 |+----+-----------------+---------------------+但是當我嘗試使用 Laravel 執行此查詢時,我返回一個空數組 []dump($phone_numbers);// 0 => "+1234567819"// 1 => "+19873216154"// 2 => "+15984989898"$phone_numbers = implode("','", $phone_numbers);dump($phone_numbers);// +1234567819','+19873216154','+15984989898dump("SELECT id, reply_text, sending_time FROM sms_sender_inbox_replies WHERE phone_number IN ('$phone_numbers') AND id IN ( SELECT MAX(id) FROM sms_sender_inbox_replies GROUP BY phone_number )");// SELECT id, reply_text, sending_time// FROM sms_sender_inbox_replies// WHERE phone_number// IN ('+1234567819', '+19873216154', '+15984989898')// AND id IN (// SELECT MAX( id ) // FROM sms_sender_inbox_replies// GROUP BY phone_number// )$replies = DB::connection('second_connection') ->select(" SELECT id, reply_text, sending_time FROM sms_sender_inbox_replies WHERE phone_number IN (':phone_numbers') AND id IN ( SELECT MAX(id) FROM sms_sender_inbox_replies GROUP BY phone_number ) ", ['phone_numbers' => $phone_numbers]);dump($replies);// []
Laravel 中的原始查詢沒有得到任何結果
慕蓋茨4494581
2021-11-05 11:00:56