我需要在一个月内计算重新访问的客户。这意味着需要计算一个月内表中有多个条目的customer_id。 我的查询仅显示总客户。 答案 0 :(得分:1) 只需使用 如果您想获得多少客户: 或使用子查询获取客户数: 答案 1 :(得分:0) 另一种检查月份的方法: 答案 2 :(得分:0) 您可以通过其他方法解决此问题。
您可以创建单独的表或将列(已访问)添加到登录表中。
每当用户登录时,访问量就会增加一。 每当用户登录时,此访问字段就会增加一个 答案 3 :(得分:0) 也许以这种方式 通过此操作,您将获得一个整数,该整数代表特定用户记录访问的总次数 $count_customer_current_month = DB::table("customer_entry")->whereRaw('MONTH(date) = ?',
[$currentMonth])->count();
4 个答案:
group by customer_id having COUNT(customer_id) > 1
$entry_customers = DB::table("customer_entry")
->whereRaw('MONTH(date) = ?', [$currentMonth])
->groupBy('customer_id')
->havingRaw("COUNT(customer_id) > 1")
->selectRaw('COUNT(customer_id) AS entry_count, customer_id');
$entry_customers->get()->count() // count the collections.
DB::table(DB::raw("({$entry_customers->getSql()}) AS entry_customer"))
->mergeBindings($entry_customers)
->count();
DB::table("customer_entry")->whereMonth('date', '=',$currentMonth)->select(DB::raw('COUNT(customer_id)'))->groupBy('customer_id')->havingRaw("COUNT(customer_id) > 1")->get()
架构
$table->bigIncrements('id');
$table->unsignedBigInteger('user_id')->unique();
$table->integer('visited')->default('0');
Model::selectId($userId)->whereMonth('visit', '=', $month)->count();
user