How to select between one hour and another in SQL

Asked

Viewed 32 times

0

I need to solve a simple exercise asking to inform the amount of books sold between 13h and 17h30 of all dates.

I was able to pull between 1:00 and 5:00 but not with the minutes "5:30".

I did so:

SELECT SUM(quantidade) 
FROM notafiscal WHERE extract(hour FROM data_compra) BETWEEN 13 AND 17;

I tried using hour_minute instead of hour and by '17:30' but returns as null any result.

  • What is the type of column?

1 answer

0


Try to convert to text:

SELECT SUM(quantidade) 
FROM notafiscal 
WHERE DATE_FORMAT(Data_compra, '%T') BETWEEN '13:00:00' AND '17:30:00'

Browser other questions tagged

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