Suppose we have a table named table1:
id name event date 1 name1 f 2010-02-26 21:49:46 2 name2 f 2011-01-21 14:30:26 3 name3 f 2010-05-25 20:51:07 4 name2 r 2011-03-21 21:49:46 5 name4 t 2011-09-15 21:30:26 6 name2 t 2010-01-20 13:07:55 7 name2 t 2011-02-24 20:51:09 8 name1 r 2011-05-20 16:07:55 9 name2 r 2009-07-23 07:51:11 10 name2 r 2011-09-20 21:49:46 A) So I want the result to be in 4 columns:
name f r t name1 f:1 r:1 t:0 name2 f:1 r:3 t:2 B) moreover I want to be order in relation with the bigest sum of f2, r0.5, t*4 DESC:
C) moreover I want to count the number of events only in a specific period for example last week, month, last 6 months. Can you embeded the below SQL query to yor answer? Are there more types of intervals like months years or hours?
SELECT * FROM table1 WHERE date BETWEEN DATE_SUB(CURDATE(), INTERVAL 1 WEEK) AND CURDATE()