I have a MySQL table, each row represents a curl request made within php. With the column names (ip, http_code, time_checked)
SELECT *
FROM proxy_stastistics
WHERE time_checked > UNIX_TIMESTAMP( NOW() - INTERVAL 24 HOUR )
Im using the above query at the moment to return only the records made in the last 24 hours, but i'm wanting to return only one row per unique IP address but at the say time creating 2 additional columns where any http_code = 200 or http_code = 0 as an increment column.
so i would get something like this
IP | 200 | 0 | 404
192.168.0.1 | 100 | 5 | 1
192.168.0.2 | 84 | 3 | 0
EDIT after reading up on MySql pivot tables i was able to create the following query to achieve what i wanted to do.
SELECT ip_address,
SUM(http_code = '200') AS http200,
SUM(http_code = '0') AS http0,
SUM(http_code = '404') AS http404
FROM proxy_stastistics
WHERE time_checked > Unix_timestamp(Now() - interval 24 hour)
GROUP BY ip_address