Well. I don't really know if what I want is possible by the way I built my table. Let me explain.
I got this table
CREATE TABLE `kill_log` (
`time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`killer_cid` int(11) NOT NULL,
`killed_cid` int(11) NOT NULL,
`map` varchar(25) NOT NULL DEFAULT '',
KEY `killer_cid` (`killer_cid`),
KEY `killed_cid` (`killed_cid`)
)
When somebody kills someone in the game, it gets registered, and in the end of each month I need to calculate the winner by calculating how many kills and how many times he was killed.
I tried building up a query with group, but I couldn't figure out how to calculate how many times he was killed..
SELECT killer_cid as char_id, count(killer_cid) as kills
FROM kill_log
WHERE `time` >= (NOW() - INTERVAL 30 DAY)
GROUP BY killer_cid
ORDER BY count(killer_cid) DESC
But what I really need is to show
char_id | kills | deaths | points (kills - deaths)
How could I do this? Should I create a different table and register stuff in another way?
I think I could register when they get killed and when they die, and then group by char_id and count if they killed or died.. but.. is by this method possible?