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