How to regroup the queried data?

about the design of the fields of a table a during the design phase of the data table during the development of the project, including the creation time and status of the id,name,.
first of all, according to my business needs, I need to group the data by time, which can be achieved by attaching the code:
(I am using the native database query statement of php)

$data = $request->getQueryParams();                                   
$from = $data["from"];                                                
$to = $data["to"];                                                    
$res = Plan::query()                                                  
    ->where("user_id",$userid)                                        
    ->where("status","!=",-1)                                         
    ->whereBetween("create_time",[$from,$to])                         
    ->selectRaw("DATE_FORMAT(create_time,"%Y-%m-%d") as date")        
    ->selectRaw("COUNT(*) as count")                                  
    ->groupBy("date")                                                 
    ->orderBy("date","desc")                                          
    ->get();                                                             

data return format:

[
    {
        "date": "2018-10-21",
        "count": "2"
    },
    {
        "date": "2018-10-20",
        "count": "2"
    }
]

then, I want to design another query method, which is also my requirement, because I design a status status field in my field, and the status may be 010, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1. I lost-1 to the data Filter, mainly because I wanted to group the status under the condition of date grouping, that is, the second grouping. The expected data result is:
(over counts for status1, no counts for status 0)
{

    "date": "2018-10-21",
    "over": 3,
    "no": 1

}
but I have not thought of a good solution, hoping to provide ideas and code

Sep.08,2021

Plan::query()                                                  
    ->where('user_id', $userId)                                        
    ->where('status', '!=', -1)                                         
    ->whereBetween('create_time', [$from, $to])                         
    ->selectRaw('DATE_FORMAT(create_time, "%Y-%m-%d") AS date')        
    ->selectRaw('COUNT(*) AS count')
    ->selectRaw('status')                                      
    ->groupBy('date', 'status')                                      
    ->orderBy('date', 'desc')                                          
    ->get();                                                             
Plan::query()                                                  
    ->where('user_id', $userId)                                        
    ->where('status', '!=', -1)                                         
    ->whereBetween('create_time', [$from, $to])                         
    ->selectRaw('DATE_FORMAT(create_time, "%Y-%m-%d") AS date')        
    ->selectRaw('SUM(IF(status=1, 1, 0)) AS over')
    ->selectRaw('SUM(IF(status=0, 1, 0)) AS no')
    ->groupBy('date')                                      
    ->orderBy('date', 'desc')                                          
    ->get();                                                             

since there are only three kinds of states (0min1 br 1) and-1 is Filter, there are only states 0 and 1 in the result set

so SUM (status) is actually the number of status=1, and COUNT (*) minus SUM (status) is the number of status=0

// 
->selectRaw('SUM(status) as over') 

// 
[
    {
        "date": "2018-10-21",
        "count": "2",
        "over": "1",
    },
    {
        "date": "2018-10-20",
        "count": "2",
        "over": "0",
    }
]

// ,count - over = no
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-1be6653-317df.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-1be6653-317df.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?