久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

CodeIgniter - 按順序分組,但未按預期工作

CodeIgniter - Group by with order by not working as expected(CodeIgniter - 按順序分組,但未按預期工作)
本文介紹了CodeIgniter - 按順序分組,但未按預期工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

所以我得到了這個查詢:

So I got this query:

    $CI->db->where('user_id', $CI->session->userdata('user_id'));
    $CI->db->where('amount >', 0);
    $CI->db->order_by('ur_time', 'desc');
    $CI->db->group_by('resource_id');
    $query = $CI->db->get('users_resources');
    $resources = $query->result();

我的問題是:order_by 'ur_time' 不起作用.如果我有 2 行,一個金額為 10000 和 ur_time 1384303464,另一行金額為 100 和 ur_time 1384304656,結果我仍然得到金額為 10000 的行.

My problem is: The order_by 'ur_time' doesn't really work. If I got 2 rows, one with amount 10000 and ur_time 1384303464 and another row with amount 100 and ur_time 1384304656 I still get the row with amount 10000 as result.

我做錯了什么?

也許我需要解釋一下.假設我有一些行:

Maybe I have to explain it a bit. Let's say I got some rows:

ur_id | ur_time     | user_id | resource_id | amount

1     | 1384304656  | 1       | 1           | 100
2     | 1384303464  | 1       | 1           | 10000
3     | 1384303464  |?1       | 2           | 200
4     | 1384304656  | 1       | 2           | 20000

我想得到的結果是:兩行,ur_id 為 1 的行和 ur_id 為 4 的行,因為對于每個 resource_id,我想要具有最高 ur_time 的行.我希望現在清楚了.

What I'd like to get here as result: Two rows, the one with ur_id 1 and the one with ur_id 4 because for each resource_id I want the row with the highest ur_time. I hope it's clear now.

PS:我需要數量 > 0 子句,因為可能有負數量,但我不希望它們出現在結果中.

PS: I need the amount > 0 clause because there can be negative amounts but I don't want them in the result.

推薦答案

嘗試將其添加到您的查詢中,看看它們是否會合并到您的選擇語句中

Try adding this in your query see if they will combine in your select statement

$CI->db->select('*');
$CI->db->select_max('ur_time' , 'max_ur_time'); // this will produce max(ur_time) as max_ur_time
$CI->db->where('user_id', $CI->session->userdata('user_id'));
$CI->db->where('amount >', 0);
$CI->db->order_by('ur_time', 'desc');
$CI->db->group_by('resource_id');
$query = $CI->db->get('users_resources');
$resources = $query->result();

這篇關于CodeIgniter - 按順序分組,但未按預期工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Add programmatically a downloadable file to Woocommerce products(以編程方式將可下載文件添加到 Woocommerce 產品)
Get today#39;s total orders count for each product in Woocommerce(獲取今天 Woocommerce 中每種產品的總訂單數)
Add Custom registration fields in WooCommerce and phone field validation issue(在 WooCommerce 和電話字段驗證問題中添加自定義注冊字段)
Add a select field that will change price in Woocommerce simple products(在 Woocommerce 簡單產品中添加一個將更改價格的選擇字段)
Add custom columns to admin products list in WooCommerce 3(在 WooCommerce 3 中將自定義列添加到管理產品列表)
Customizing checkout quot;Place Orderquot; button output html(自定義結帳“下訂單按鈕輸出html)
主站蜘蛛池模板: 国产精品无码专区在线观看 | 免费一级黄 | 91精品国产色综合久久 | 成人妇女免费播放久久久 | 91资源在线| 狠狠干天天干 | 国产特一级黄色片 | 欧美另类视频在线 | 国产91亚洲精品一区二区三区 | 亚洲成av| 五月激情婷婷六月 | 久久精品国产亚洲一区二区 | 欧美一极视频 | 精品一区二区三区91 | 亚洲h在线观看 | 国产精品久久久一区二区三区 | 欧美一区 | 夜夜爽99久久国产综合精品女不卡 | 国产草草视频 | 天天操妹子 | 久久精品国产亚洲一区二区三区 | 亚洲国产成人精品一区二区 | 欧美激情在线观看一区二区三区 | 欧美日高清视频 | 欧美精品乱码久久久久久按摩 | 国产精品一区二区av | 精品国产31久久久久久 | 亚洲色视频| 色视频在线观看 | 澳门永久av免费网站 | 国产精品色一区二区三区 | 精品国产高清一区二区三区 | 亚洲综合区 | 91在线区| 亚洲av毛片 | 亚洲三区在线观看 | 中文欧美日韩 | 中文字幕一区二区三区不卡在线 | 亚洲精品自在在线观看 | 免费在线观看成人 | 四虎影视|