我有一個資料庫表,其中有一列包含字符和數字混合的資料。我想實作的是選擇小數點前的所有字符和數字。以下是資料在列中的情況:
PO995.1
PO995.2
PO995.3
PO995.4
雄辯的查詢
$po_number= DB::table('supplierorders')
->select('supplierorders.*')
->orderby('po_number','asc')
->get();
我只想選擇PO995并忽略.xx有沒有辦法在我的查詢中實作這一點?
謝謝。
uj5u.com熱心網友回復:
是的,您可以嘗試使用Laravel Collection Map和 PHP 字串expand ()。
替換field_name為表中的欄位
$po_number= DB::table('supplierorders')
->select('supplierorders.*')
->orderby('po_number','asc')
->get()
->map(function($item)
{
return explode('.', $item->field_name)[0];
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/349327.html
