Filter data by period

Asked

Viewed 137 times

0

I’m having trouble putting together a sql to my system.

I have a table anuencias with a column status. I want to list data where on status contain words "signature", "ready to send" and "cartorio" but that this data is of a certain period that the user informs.

I have a column called created where the date and time of each record that could be used to filter the data by period is recorded using the function between.

I tried to do something like this, but the query returns all the records.

SELECT * FROM anuencias 
WHERE status like '%ASSINATURA%' OR 
   status like '%PRONTA PRA ENVIO%' OR 
   status like '%CARTORIO%' OR 
   created BETWEEN '2017-08-01' AND '2017-08-31'
  • 1

    puts the code you made and/or the tables you have to make it easier for us.

1 answer

1


Actually you need that obligatorily the date is between the two defined; then the select would look like this:

SELECT * FROM anuencias 
WHERE (status like '%ASSINATURA%' OR status like '%PRONTA PRA ENVIO%' OR status like '%CARTORIO%')
   AND created BETWEEN '2017-08-01' AND '2017-08-31'

Note: in the question you say you want "list data where in status contain words 'signature', 'ready to send' and 'cartorio'" , but your select brings any occurrence of one of the words in status. Should you want the status contains the three expressions, the select correct would be the below:

SELECT * FROM anuencias 
WHERE status like '%ASSINATURA%' AND
   status like '%PRONTA PRA ENVIO%' AND
   status like '%CARTORIO%' AND 
   created BETWEEN '2017-08-01' AND '2017-08-31'

Browser other questions tagged

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