Here is the problem,
I've got a very large table like this :
Epoch_time MAC
-------------------------------------
1395275303 | 84:xx:xx:xx:xx:xx
1395275423 | bc:xx:xx:xx:xx:xx
1395275423 | 84:xx:xx:xx:xx:xx
And I want to count the unique MAC Adress per Hour. So I did this
SELECT Count(DISTINCT mac_adress), FROM_UNIXTIME(`date_ecoute`, '%d.%m.%Y.%H') as ndate FROM box1
WHERE date_ecoute > unix_timestamp(CURRENT_TIMESTAMP - INTERVAL 2640 MINUTE)
AND signal_strength >= -60 group by ndate
That works pretty well, here is the result per hour :
Count(DISTINCT mac_adress) ndate
--------------------------------------
2 | 20.03.2014.03
8 | 20.03.2014.06
11 | 20.03.2014.07
The problem is that some hours there are no line in my table so as you can see on the result above there are no line for 20.03.2014.04 or even 05. I would like this output :
Count(DISTINCT mac_adress) ndate
--------------------------------------
2 | 20.03.2014.03
0 | 20.03.2014.04
0 | 20.03.2014.05
8 | 20.03.2014.06
11 | 20.03.2014.07
I tried IS NULL
, IF NULL
, LEFT JOIN
, COALESCE
. I'm not pro with Sql...
IFNULL(Count(DISTINCT mac_adress),0) // At the beginning, Doesn't work