S
S
shushpanio2018-09-17 14:08:08
SQL
shushpanio, 2018-09-17 14:08:08

How to get the number of repetitions?

I understand that the basis of the basics is wildly stupid and I ask for your help.
We have a table that contains the following fields:
Call_date contains the Date
AON call time contains the caller's number . It is
necessary to receive an output by the number of calls from clients who called back within a day from the moment of the last call
. The output should receive the format
Date | Number of repeated calls

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Tabris17, 2018-09-17
@shushpanio

Something like this

SELECT Date, COUNT(*)
FROM (SELECT old.*
      FROM MyTable old, MyTable new
      WHERE new.AON = old.AON
      AND new.Date = DATEADD (DAY , -1, old.Date)
     )
GROUP BY Date

I
idShura, 2018-09-17
@idShura

I don't know MS Sql syntax, but probably something like this:

select t1.Call_date 
       t1.AON
       count(*) cnt
  from tab1 t1
       left join tab1 t2 ON t2.AON = t1.AON 
 where t2.Call_date between t1.Call_date 
                        and t1.Call_date + 1
 group by t1.Call_date 
          t1.AON

V
Vapaamies, 2018-09-17
@vapaamies

Usually in SQL you can write count(distinct поле).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question