R
R
Renat Abdrakhmanov2021-12-07 20:45:48
PostgreSQL
Renat Abdrakhmanov, 2021-12-07 20:45:48

SQL how to count the number of visits?

Hello!

I have purchase data:
customer ID (ID_Customer, time of purchase (date_transactions, store number (id_store), receipt ID (id_receipt).

Please tell me how to calculate the number of visits by the customer to the store?

He could buy several checks for one trip to shop.So a visit is a purchase within one hour in one

store.I guess you need to use date_trunc

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly, 2021-12-10
@TonyWrong

with tt as (
select ID_Customer id, id_store,  date_trunc('hour', date_transactions) trun 
from transactions t
)
select id,  id_store, count(id)
from tt
group by 1,2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question