Select to know customers without service in the last 30 days plsql

Asked

Viewed 865 times

1

I have the following columns: CODCLI, CLIENT AND DTULTCOMP I need to know which customers you haven’t bought in the last 30 days. the DTULTCOMP column is in DATE format Table: PCLIENT

  • These columns are in which table(s))?

  • Which database are you using? Mysql, Oracle, MSSQL? Have you tried something? I assume you are, and your problem is in condition WHERE, that you need to be the DTULTCOMP < (AGORA - 30 dias), that’s it?

  • Oracle database.

  • That’s right, it worked out thanks

2 answers

1

If the accuracy is per month you can use the function Add_mouth, passing a negative value by removing months from the date, ex:

select * from SuaTabela 
 where SuaColuna < add_months(sysdate, -1)

If the operation needs to be in days just make a subtraction on the date of comparison, ex:

select * from SuaTabela 
 where SuaColuna < sysdate - 30

0

Select * from tabela
where DTULTCOMP is null
or DTULTCOMP < (SYSDATE - 30)

If you want to know only those who actually bought something, because there are customers who bought it a long time ago, or simply never bought it, remove the condition that tests null.

Select * from tabela
where DTULTCOMP < (SYSDATE - 30)

Browser other questions tagged

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