SELECT COUNT(*) FROM (SELECT * FROM abc WHERE col1 = xxx and col2 = xxx GROUP BY col1) AS sub WHERE col1 = xxx and col2 = xxx and col3 = xxx;
use Illuminate\Support\Facades\DB;
$subQuery = DB::table('abc')->where('col1', 'xxx')->where('col2', xxx)->groupBy('col1);
$query = DB::table(DB::raw("({$subQuery->toSql()}) as sub")) ->select(DB::raw('count(*)')) ->where('col1', 'xxx') ->where('col2', 'xxx') ->where('col3', 'xxx');
// 合并绑定参数
$query->mergeBindings($subQuery);
OR
$query->mergeBindings($subQuery->getQuery());
$query->get();