【问题标题】:how to find same id and group and count the same id on different days如何在不同的日子找到相同的ID和组并计算相同的ID
【发布时间】:2018-09-04 05:31:46
【问题描述】:

目前我有一个这样的数据库结构:-

我想要创建的(在 laravel eloquent 中)首先获取 user_id 和 date_access。然后基于例如 2018-03-07 上的日期是 3 行,所以 user_id 1 有 2 次所以 = 2018-03-07 => 2
这是因为它应该将相同的 user_id 组合在一起以使其 1 和另一个 user_id 加在一起..

我该怎么做?

【问题讨论】:

    标签: php arrays laravel eloquent


    【解决方案1】:

    你可以试试这个:

    $collections = DB::table('my_table')
                     ->select(DB::raw('count(user_id) as users'))
                     ->groupBy('date_access')
                     ->get();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多