473,386 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How can i fetch all the values in a minute from a table ?

Hi All,

I have a field createdTime in a table users with current time stamp as data type. I am trying to display the count of users in every minute in each day . By using the php loop and select query its little bit slow. How can i do this using mysql query ? Is there any method to select the values in a minute using a single query ? My aim is to display the details as

Time userCount
2012-09-28 00:00:00 5
2012-09-28 00:01:00 8
2012-09-28 00:02:00 7
2012-09-28 00:03:00 7
------------------------------------
----------------------------------
2012-09-28 00:59:00 10
2012-09-29 00:00:00 3
2012-09-29 00:01:00 10
2012-09-29 00:02:00 8
2012-09-29 00:03:00 20


( Where 5,8,7 etc are the user counts )

If anyone knows the solution,please help me to sort out this...
Thanks in advance....
Sep 29 '12 #1
3 2345
Luuk
1,047 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. select date_format(createdTime,'%Y%m%d%H%i') D, count(*) 
  2. from users 
  3. where createdTime between '2012-09-01' and '2012-10-01' 
  4. group by date_format(createdTime,'%Y%m%d%H%i');
  5.  
Please check if there is an index on 'createdTime'
if its not fast enough, please give output of the EXPLAIN followed by the query...
Sep 29 '12 #2
Hi Luuk,

Thanks for your reply..
I tried your query like
Expand|Select|Wrap|Line Numbers
  1. SELECT DATE_FORMAT( time, '%Y-%m-%d %H:%i' ) , COUNT( * ) AS userCount
  2. FROM uesr
  3. WHERE time
  4. BETWEEN '2012-08-22 00:00:00'
  5. AND '2012-08-22 23:59:59'
  6. GROUP BY DATE_FORMAT( time, '%Y-%m-%d %H:%i' )
Its working correctly..
But if a situation like no user at the time 2012-08-22 00:05:00, Can i display this value as 0 using the query ?
Currently the above query does not consider the '2012-08-22 00:05:00' because no entry for this time value..
Actually i am expecting 60*24 rows for every hours ,ie if there is no users for particular minute i would like to display that field value as 0
Is it possible with the mysql query ?

Thanks
Oct 1 '12 #3
Luuk
1,047 Expert 1GB
You should create a table which has 60*24, one for every minute.
Then you could select this table, and left join it to the results above.
Oct 2 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Larry Woods | last post by:
I have created a table that I want to fill with calculated values. I have given ID's to each cell. This must NOT be the way since I can't address these ID's. How do I store values in table cells...
2
by: agphoto | last post by:
when we do mysql_query with while and mysql_num_rows() together then while do no show the first row from table in database.. example : <? $conn = mysql_connect($DBhost,$DBuser,$DBpass) or...
2
by: sruthini | last post by:
Hi, I am doing send some values(signup form::firstname,lastname,title,organization) to mail id using javamail at the same time it should store in database, my problem is how to fetch values from...
20
by: sruthini | last post by:
Hi, I am doing send some values(signup form::firstname,lastname,title,organization) to mail id using javamail at the same time it should store in database, my problem is how to fetch values from...
7
by: riceking | last post by:
Is it possible to do the following and if so, how? In one table, I have a list of email addresses I know are bad and no longer work. Another table has a list of companies with contact people,...
1
by: san1014 | last post by:
Hi I have a table SQL> select * from nodes; NODE_ID NODE_NAME -------------------- ------------------------------ N1 Kothhapet N2 Nagole...
1
by: rahullko05 | last post by:
Hi, i am building a small forum site as my final year project & stuck in a very trivial problem. I have a table which are varchar type of data & i am trying to fetch data from table based on...
2
by: vjayis | last post by:
hi i have two tables which is named as category and subcategory .. category fieldnames 1.id 2.name 3.status
1
by: Guru S | last post by:
I haev a table "emp_details" with two fields ID,Name. and created a form "record" with text boxs adn a command button. I want to get the information from the user in these two text boxes and when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.