[snip] +---------------------------+--------------+-----------+-------------+-- --------+-------------+ | code | bin | min | ain | cin | dur | +---------------------------+--------------+-----------+-------------+-- --------+-------------+ | NONE | 103939170759 | 485089817 | 3739.1827 | 27797297 | 11681839027 |
Now, what i need todo is exclude certain info from the above NONE entry if code2 is equal to something. So for example (in php terminology): if(code == 'NONE') { if(code2 == 'DENIED') { continue; } else { bin += bytes; if(bytes > min) { min = bytes; } cin++; dur += dur; } } after that i could work out the average by dividing bin / cin for what in the report is called ain. Is there any way of achieving this via the sql query because the above is a hugely tedious way of doing it. I know mysql has an if() statement, but I have no idea how to implement it using what i want to achieve above. [/snip] Basically; SELECT SUM(IF(`code` = 'NONE', <calculation>, 0)) AS `ain` FROM `table` -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]