亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用 whereIn 和 take 函數從 laravel 中的 SQL 獲取數據?

如何使用 whereIn 和 take 函數從 laravel 中的 SQL 獲取數據?

PHP
慕勒3428872 2022-12-03 11:08:59
您可以將其類型轉換為浮點數:$value = (float) $column[1];為了確保你確實有一個浮點數,你可以嘗試像這樣檢查if (is_numeric($column[1]) && !is_int($column[1])) {    $value = (float) $column[1];}
查看完整描述

3 回答

?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

根據您的評論,我認為您需要一個分組查詢。


$userBikes = array('862549040389788','12345');


$data = DB::table('geolocation')

->whereIn('Imei', $userBikes)

->groupBy('Imei')

->selectRaw('any_value(id) as id, any_value(Lat) as Lat, any_value(Lng) as Lng, any_value(created_at) as created_at, Imei')

->get();


查看完整回答
反對 回復 2022-12-03
?
九州編程

TA貢獻1785條經驗 獲得超4個贊

如果您希望$userBikes數組中的每個元素有 1 個值,則需要進行 2 個不同的查詢。


$userBikes = array('862549040389788','12345');

$output = array();



foreach($userBikes as $imei) { 

    $data = DB::table('geolocation')

       ->where('Imei',$imei)

       ->take(1)      

       ->get()->toArray();

    array_push($output, $data)

return $output;

第二種解決方案是take(1)從查詢中刪除并過濾數據對象中的每個值。


查看完整回答
反對 回復 2022-12-03
?
函數式編程

TA貢獻1807條經驗 獲得超9個贊

您必須take(1)從查詢中刪除。

Take(1) 會將結果限制為 1 行。

所以應該是:

$data = DB::table('geolocation')
    ->whereIn('Imei',$userBikes)      
    ->get();


查看完整回答
反對 回復 2022-12-03
  • 3 回答
  • 0 關注
  • 147 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號