PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > mysql.general > Group by time range.
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Group by time range.

Réponse
 
LinkBack Outils de la discussion
Vieux 30/10/2007, 21h55   #1
Chris W
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Group by time range.

I have the following query...
SELECT CreateDate, count( * )
FROM `userprofile`
GROUP BY CreateDate


It isn't exactly what I want. Records are added to this table in 2 main
ways. First people use the web site interface to create records. In
this case, records are only added by one or 2 people and with a
significant time between record inserts. The second way is through an
import that reads data from a text file. In the second case the date on
the records will all be close together with about 60 records added per
second. What I want to do is find all the groups where the inserts all
happened with in say 10 seconds. So my group by would be more like......

GROUP BY CreateDate +- 10 SECOND


Is there a way to do this?

--
Chris W
KE5GIX

"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"

Ham Radio Repeater Database.
http://hrrdb.com
  Réponse avec citation
Vieux 30/10/2007, 22h08   #2
Baron Schwartz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Group by time range.

Hi,

Chris W wrote:
> I have the following query...
> SELECT CreateDate, count( * )
> FROM `userprofile`
> GROUP BY CreateDate
>
>
> It isn't exactly what I want. Records are added to this table in 2 main
> ways. First people use the web site interface to create records. In
> this case, records are only added by one or 2 people and with a
> significant time between record inserts. The second way is through an
> import that reads data from a text file. In the second case the date on
> the records will all be close together with about 60 records added per
> second. What I want to do is find all the groups where the inserts all
> happened with in say 10 seconds. So my group by would be more like......
>
> GROUP BY CreateDate +- 10 SECOND


Convert the date to a number of seconds, then round to the nearest 20
seconds and convert it back to a date. You can use FROM_UNIXTIME() and
UNIX_TIMESTAMP() for the conversion. You can round to the nearest 20
seconds by dividing by 20, rounding to the nearest whole number, and
multiplying by 20 again. Group by the resulting expression.

Baron
  Réponse avec citation
Vieux 30/10/2007, 23h09   #3
Peter Brawley
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Group by time range.

Chris,

What I want to do is find all the groups where the inserts all
happened with in say 10 seconds. So my group by would be more like......

Perhaps the easiest solution is to make a temp table of datetime ranges
from the resultset, then join from and group by those rowIDs.

PB

-----

Chris W wrote:
> I have the following query...
> SELECT CreateDate, count( * )
> FROM `userprofile`
> GROUP BY CreateDate
>
>
> It isn't exactly what I want. Records are added to this table in 2 main
> ways. First people use the web site interface to create records. In
> this case, records are only added by one or 2 people and with a
> significant time between record inserts. The second way is through an
> import that reads data from a text file. In the second case the date on
> the records will all be close together with about 60 records added per
> second. What I want to do is find all the groups where the inserts all
> happened with in say 10 seconds. So my group by would be more
> like......
>
> GROUP BY CreateDate +- 10 SECOND
>
>
> Is there a way to do this?
>

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 03h49.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10609 seconds with 11 queries