Created
August 31, 2018 08:12
-
-
Save markuman/269bd31ccefea5071b835897bea3d7e6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set | |
@i = - 1; | |
with list_of_dates as( | |
SELECT | |
DATE( ADDDATE(( | |
select | |
( DATE_SUB( CURRENT_DATE, | |
INTERVAL 1 MONTH ))), | |
INTERVAL @i := @i + 1 DAY )) AS dates | |
FROM | |
`action` | |
HAVING | |
@i < DATEDIFF(( | |
select | |
CURRENT_DATE ), | |
( | |
select | |
( DATE_SUB( CURRENT_DATE, | |
INTERVAL 1 MONTH ))) )), | |
actions as ( | |
select | |
created_unix as time_sec, | |
count( user_id ) as value, | |
DATE_FORMAT( FROM_UNIXTIME( created_unix ), | |
'%Y%m%d' ) as dates | |
from | |
`action` | |
where | |
user_id = 1 | |
group by | |
DATE_FORMAT( FROM_UNIXTIME( created_unix ), | |
'%Y%m%d' ) | |
order by | |
created_unix ) select | |
list_of_dates.dates, | |
ifnull( actions.time_sec, | |
UNIX_TIMESTAMP(list_of_dates.dates)) as time_sec, | |
ifnull( actions.value, | |
0 ) as value, | |
'commits' as metric | |
from | |
list_of_dates | |
left join actions on | |
( list_of_dates.dates = actions.dates ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment