I keep a track of whom is logging onto our local server as shown in the database below.
My DB Structure is:
user logon reconnect
mike 2015-07-09
mike 2015-07-09
mike 2015-07-09
mike 2015-07-09
john 2015-07-09
john 2015-07-09
john 2015-07-09
pete 2015-07-09
pete 2015-07-09
pete 2015-07-09
matt 2015-07-09
sara 2015-07-09
I am trying to build a query that gets how many DISTINCT users logon or reconnect during one day, Data should look like this:
date totalcount
2015-07-09 4
Basically its counted 4 users on 2015-07-09.
Heres my query that shows the last 14 days logons, but does not include reconnects
SELECT DATE(logon) AS `date`, COUNT(DISTINCT `user`) AS totalcount
FROM user_logons
GROUP BY DATE(logon)
ORDER BY DATE(logon) DESC
LIMIT 14
Shows:
date totalcount
2015-07-09 399
2015-07-08 513
2015-07-07 524
2015-07-06 456
2015-07-05 213
2015-07-04 300
2015-07-03 484
2015-07-02 525
2015-07-01 539
2015-06-30 536
2015-06-29 481
2015-06-28 289
2015-06-27 423
2015-06-26 509
I'm wanting to total both columns, combining them and then grouping by date. I'm having trouble writing the query. Please help.
NULL? If so, you can useGROUP BY COALESCE(logon, reconnect)