Conteggio date

M

Mrb

Salve a tutto il news,
ho delle difficolta nel calcolo dei giorni.... mi spiego, ho una tabella
nella quale ci sono campi "data" e "nominativo". Nella stessa tabella sono
già stati inseriti i nomi e per ogni nome ci sono delle date consecutive e
non,esempio:
PIPPO 23/02/08
PIPPO 24/02/08
PIPPO 25/02/08
PIPPO 28/02/08
PIPPO 01/04/08
PIPPO 02/04/08

PIPPA 28/09/08
PIPPA 29/09/08
PIPPA 30/09/08
PIPPA 01/10/08
PIPPA 02/10/08

Io vorrei capire come fare il conteggio dei giorni consecutivi o quelli
singoli per i diversi nomi se fosse possibile con un Query, come il seguente
risultato:

PIPPO 3 che corrispondono al 23 24 25/02/08
PIPPO 1 che corrisponde al 28/02
PIPPO 2 che corrispondono al 01 02/04

PIPPA 5 che corrispondono al 28 29 30/09 01 02/10


ringrazio anticipatamente tutti,
 
M

Michel Walsh

I hope you won't mind if I answer in English, my "writing in Italian" skill
is quite poor.

To find continuous sequences, or 'strikes', a possible solution is to group
on the integer value less its rank.

A first query, to compute the rank:


-----------------------------
SELECT a.type, a.theDate, COUNT(*) AS rank
FROM tableName AS a INNER JOIN tableName AS b
ON a.type=b.type AND a.theDate >= b.theDate
GROUP BY a.type, a.theDate
-------------------------------


save it as, say, Query1. I assumed you table name is tableName and its two
fields are type and theDate.



type theDate rank
PIPPO 23/02/08 1
PIPPO 24/02/08 2
PIPPO 25/02/08 3
PIPPO 28/02/08 4
PIPPO 01/04/08 5
PIPPO 02/04/08 6

PIPPA 28/09/08 1
PIPPA 29/09/08 2
PIPPA 30/09/08 3
PIPPA 01/10/08 4
PIPPA 02/10/08 5





And, as said, the second query 'simply' groups on theDate-rank:

------------------------------------
SELECT type,
MIN(theDate) AS startOfStrike,
MAX(theDate) AS endOfStrike,
COUNT(*) AS lengthOfStrike
FROM query1
GROUP BY type, thenDate-rank
--------------------------------------



Indeed, before the grouping, just consider date - rank:
date-rank
PIPPO 23/02/08 1 : 22 feb 2008
PIPPO 24/02/08 2 : 22 feb 2008
PIPPO 25/02/08 3 : 22 feb 2008
PIPPO 28/02/08 4 : 24 feb 2008
PIPPO 01/04/08 5 : 28 mar 2008
PIPPO 02/04/08 6 : 28 mar 2008



so, it should now be evident why we group on date-rank


group (PIPPO, date-rank= 22 feb 2008) starts the 23/02/o8, ends the 25,
and has 3 records (days) in that group
group (PIPPO, date-rank=24 feb 2008) starts the 28/02/08, ends the same, has
only one record (one day)
etc.



Vanderghast, Access MVP
 
M

MRB

Michel Walsh, ti ringrazio tantissimo mi sei stato di greande aiuto grazie,
P.S. Mi scuso se nn ti scrivo in Inglese, nemmeno io sò parlare e scrivere
bene l inglese, e grazie ancora.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top