Select dates based on the total sum of a given column

Asked

Viewed 66 times

2

Good night. Based on the example registration attached, I would have to select all dates that are equal and are in the same restaurant and the sum of the amount is > 10, because I need to disable these dates from my datepicker.

inserir a descrição da imagem aqui

1 answer

3


Fala Marlon,

I believe 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");
  • Thanks a lot Thiago. It worked perfectly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.