Filter data by period

0

I'm having problems mounting an sql to my system.

I have a anuencias table with a status column. I want to list data where in status contain words "signature", "ready for sending" and "cartorio" but that these data are of a certain period that the user informs.

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

I tried to do something like this, but the query returns all 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'
    
asked by anonymous 09.08.2017 / 20:58

1 answer

1

You actually need to the date be 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 "to list data where in the status contain words 'signature', 'ready for sending' and 'cartorio'" , but your select > brings any occurrence of one of the words in status . If you want the status to contain all three expressions, the correct would be as 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'
    
09.08.2017 / 21:09