Laravel is written in group after using the where statement.

there are three fields (: score (score) and userid,subject (discipline) in the data table tbscore. The effect I want to achieve is:

select sum(score),subject from (select score,subject from tbscore where userid in(1,2,3)) group by subject

that is, you want to filter out the result set first, and then group by, the result set. How to write

in laravel?
Feb.28,2021

try this

$row = DB::table('tbscore')
    ->select(DB::raw('count(score) as score, subject'))
    ->whereIn('userid', [1,2,3])
    ->group ('subject')
    ->get();

Database-- query Builder

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3be3d-2c2b5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3be3d-2c2b5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?