SQL select question for hourly data I need help with MySQL statement . I need to know how many calls come in every hour. This is what we have so far. 

    SELECT
sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 09:00:00' and '2015-12-02 10:00:00' THEN 1 else 0 END) as Hour2,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour3,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour4,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour5,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour6,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour7,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour8,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour9,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour10,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour11,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour12,
    sum(CASE WHEN session.creationtimestamp BETWEEN '2015-12-02 00:00:00' and '2015-12-02 23:00:00' THEN 1 else 0 END) as Hour13
    FROM session
    Inner Join mxuser
    ON session.extensionid2=mxuser.extensionid
    WHERE
    mxuser.userprofilename = 'Team1'
    And session.legtype1 = 2
    AND session.Legtype2 = 1
    or session.Legtype2= 2
I will call creationtimestamp simply ts...

SELECT  FLOOR(UNIX_TIMESTAMP(ts)/3600) AS start_of_hour,
        COUNT(*)
    FROM session ...
    GROUP BY FLOOR(UNIX_TIMESTAMP(ts)/3600);


If you need to "pivot" the output into 24 columns, then generate the code from http://mysql.rjweb.org/doc.php/pivot .