ThinkPHP distinct count 統計查詢寫法

下面示例是使用 ThinkPHP 6 查詢數據表某個字符不重複記錄的總個數:

use think\facade\Db;
...
$count_res = Db::connect('zs')->table('member_luck_log')
    ->where('set_id', $set_id)
    ->where('set_item_id', $item_id)
    ->field(Db::raw('COUNT(distinct(`vipcode`)) as `count_sum`'))
    ->find();
echo $count_res['count_sum'];

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章