I have two tables, table1 is as following, id is primary key, table2_id is foreign key
id date aid table2_id message
1 2014-03-19 16:21:02 121 1 login from xxxx
2 2014-03-20 14:00:32 123 2 decrease budget
3 2014-03-20 18:00:32 121 2 increase budget
4 2014-03-21 16:21:02 121 3 login from xxxx
5 2014-03-21 16:21:02 121 3 login from xxxx
6 2014-03-22 10:21:02 121 2 increase budget
table2 is a type table
id type
1 login
2 change_budget
3 search
I need to analyse the relationship between activity change_budget and other activity. I am not sure how could I deal with the big data solution, but, anyway, following is an idea of mine:
I try to write SQL for each time one aid change_budget, count the all other actions of this aid within one day. if one aid have a change_budget at 2014-03-14 16:21:02, I need all the action of this aid from 2014-03-13 16:21:02 to 2014-03-14 16:21:02. Then, group by the action and count.and selected table will be look as following:
aid login search change_budget
121 1 0 1
123 0 0 -1
121 0 2 1
-1 means change_budget is decrease,1 means increase. Other number is how many time this action of this aid has happen within oneday before this aid change_budget happens.
Anyone can teach me how to write this?