Answer the question
In order to leave comments, you need to log in
How to select the date of the last transaction (so that this transaction is 7 days ago)?
help solve the problem plz.
There are services on which transactions take place, I need to select inactive services. A service is considered inactive if there were no transactions on it for a week. How can I choose these services? I tried this, but not that ... it gives me a range of 6 days before today, but I want the output to have only the date 7 days ago.
select
s.id as servie_id,
s.name as servie_name,
max(to_timestamp(s.created_at))::date as last_trans_date
from services
where to_timestamp(s.created_at)::date >= current_date - 6
group by 1,2
order by 1
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question