Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Heffer
May 1, 2003

Opius posted:

Thanks for the help with the voting query, but I have another question regarding grouping DATETIME fields.

I've got a table called 'views' that's laid out like so:
code:
INT content_id, DATETIME added
If I wanted to generate a report showing the most popular time of day for views, I can do something like this:
code:
SELECT
	HOUR(added) AS hour,MINUTE(added) AS minute,COUNT(content_id) AS count
FROM
	`views`
GROUP BY
	`hour`,`minute`
My question is: is there anyway to group results in sets of 10 minutes, rather than single minutes in the query?

Ideally, I'd like to be able to plot the results out like how Steam does.

I've had a brief look at the INTERVAL function, but it's hard to find examples of how to use this in a GROUP query.

There are probably more elegant ways to do this, but I've done something similar by taking the Unix time ticks and dividing it by the unit of time in seconds. If the division doesnt give a whole integer, truncate it to an integer. Multiply it back by your unit of time, and you should have everything grouped up with 10 minute time units.

Adbot
ADBOT LOVES YOU

Heffer
May 1, 2003

Sybase is very similiar to SQL Server. (SQL Server descends from Sybase if I remember it right). Querying against sys_objects would be your best bet.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply