sql,query Hi, Few days ago ,was someone(i try out to find in my e-mail list ...but i didn't find him) which was wish to calculate some fields using variables.... I don't know if this person it's solved his problem but today i meet a similarly situation and i solved in the next way :
TABLE DEFINITION : ID INT(4),A INT(4),B INT(4) DATA ON TABLE : ID , A , B ----------- 1,1,0 1,1,0 1,2,1 2,2,1 2,0,2 2,0,2 The statement is: SELECT ID,(SUM(CASE WHEN A>0 THEN A ELSE 0 END)+COUNT(CASE WHEN A>0 THEN 1 END))/SUM(CASE WHEN B>0 THEN B ELSE 0 END) FROM test GROUP BY ID; Of course,it can be used and IF() but CASE() it's more flexible. Regards, Gelu _____________________________________________________ G.NET SOFTWARE COMPANY Permanent e-mail address : [EMAIL PROTECTED] [EMAIL PROTECTED] --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php