Page 1 of 1

some db statistics and order

Posted: Fri Sep 03, 2010 12:21 pm
by adamrain
ok i have two things i need to do with a table in db which is called relation, it represents relations between a lot or other tables.

first thing i need is statistics of last created relations by date somthing that will output like "comments per week 00.9,less then last week".

second thing i need is to call just the last 5 rows of the table (here i can do the rest and output the data any way i want).

Re: some db statistics and order

Posted: Fri Sep 03, 2010 3:42 pm
by Jonah Bron
To calculate the comments per week, just divide the number of comments by the amount of time it's been up.

Re: some db statistics and order

Posted: Sat Sep 04, 2010 6:38 am
by adamrain
ok thats helpful thank you

but how do i call the last 5 rowes of a table in mysql?

Re: some db statistics and order

Posted: Sat Sep 04, 2010 7:55 pm
by Jonah Bron
Assuming you have a auto-increment column `id`, the SQL will look like this:

Code: Select all

SELECT * FROM my_table ORDER BY id DESC LIMIT 5

Re: some db statistics and order

Posted: Tue Sep 07, 2010 7:19 am
by adamrain
thank you thats awsome!
(i always use id its a comfortable way to manipulate data)