Select dates based on the total sum of a given column [closed]

2

Good evening. Based on the example sample file attached, I would have to select all the dates that are the same and are in the same restaurant and that the sum of the quantity is > 10, because I need to disable those dates from my datepicker.

    
asked by anonymous 20.07.2016 / 03:18

1 answer

3

Speak Marlon,

I think you need something like this:

SELECT 
    t.restaurante,
    SUM(t.quantidade) AS quantidade,
    t.dataReserva
FROM
    teste t
WHERE 
    t.dataReserva >= NOW()
GROUP BY t.dataReserva, t.restaurante;

Laravel

$reservas = teste::select("restaurante", DB::raw("SUM(t.quantidade) AS quantidade"), "dataReserva")
->where("dataReserva", ">=", date("Y-m-d"))
->groupBy("dataReserva", "restaurante");
    
20.07.2016 / 04:06