tags:

views:

99

answers:

3

I'm not sure how create a right query to get the result I'm looking for. What I have is 2 tables. first has ID, Name columns and second has date and adminID, which is referenced from table 1 column ID. Now, what I want to get is basically number of times each admin loged in per day during the month.

ID  |  Date
------------------
4   |  2010/03/01
4   |  2010/03/04
4   |  2010/03/04
4   |  2010/03/05
4   |  2010/03/05

From structure like this one I want to get per day and month data so result would be similar to 1, 2, 2 march total 5 for admin 4:

ID  |  Date       | Count
--------------------------
4   |  2010/03/01 | 1
4   |  2010/03/04 | 2
4   |  2010/03/05 | 2
+1  A: 

Try this:

  SELECT COUNT(*), a.name, DATE(l.date)
    FROM admin a
   INNER
    JOIN logins l ON l.admin_id = a.id
   WHERE l.date > start_date AND l.date < end_date
GROUP BY a.name, DATE(l.date)
Justin Ethier
This query did exactly what I was looking for. Thank you every body who responded. SELECT partnerid AS ID, DATE_FORMAT(date, '%y/%m/%d') AS date, COUNT(*) FROM dispatchGROUP BY partnerid, DATE_FORMAT(date, '%y/%m/%d')
Gil
I guess now the question is if I pass 10/02/ to the query and use "like" how would it be possible to get all the range of dates in given month. So let say the result could be similar to<table><tr><td>date</td><td>num. of visits</td></tr><br /><tr><td>10/02/1</td><td>14</td></tr><br /><tr><td>10/02/2</td><td>24</td></tr><br /><tr><td>10/02/3</td><td>0</td></tr><br /><tr><td>10/02/4</td><td>7</td></tr><br /></table>Thank you for help guys.
Gil
I figured it out finally. Here is the query:SELECT id AS ID, DATE_FORMAT(date, '%y/%m/%d') AS date, count(date) FROM dispatch WHERE date LIKE '%2010-02%' GROUP BY id, DATE_FORMAT(date, '%y/%m/%d')
Gil
A: 

EDIT: this is working, tested:

SELECT count(ID) AS day_count,ID,Date FROM Table GROUP BY Date;

Table:

id  date
4   2010-04-13
4   2010-04-13
4   2010-04-23
4   2010-04-11
4   2010-04-17
4   2010-04-17
4   2010-04-17

Outputs:

day_count   id  date
1   4   2010-04-11
2   4   2010-04-13
3   4   2010-04-17
1   4   2010-04-23
Ben
A: 

select id,count(*) as numRec ,date from tablename group by date order by newRec

sam