SELECT `cms`.`vote_values`.`user_id`,`cms`.`vote_values`.`username`,`ip`, count(*) as cnt,
count(CASE WHEN `user_vote`=5 THEN 1 ELSE NULL END) as cnt5,
count(CASE WHEN `user_vote`=4 THEN 1 ELSE NULL END) as cnt4,
count(CASE WHEN `user_vote`=3 THEN 1 ELSE NULL END) as cnt3,
count(CASE WHEN `user_vote`=2 THEN 1 ELSE NULL END) as cnt2,
count(CASE WHEN `user_vote`=1 THEN 1 ELSE NULL END) as cnt1,
`user_posts`,DATE_FORMAT(FROM_UNIXTIME(`user_regdate`), '%e %b %Y') AS 'date_formatted',`user_avatar`,`user_email`
FROM `cms`.`vote_values` left join `test`.`phpbb_users`
on `cms`.`vote_values`.`user_id`= `test`.`phpbb_users`.`user_id`
where `vote_id`=5 GROUP BY `cms`.`vote_values`.`user_id` ORDER BY `vote_values`.`ip` ASC