ericsante Posted December 26, 2006 Share Posted December 26, 2006 I have a table called TransResult and I have 2 data fields in it. I want to get the percentages for the 2 possiable values in TransResult and I want this done by date, so I can go backwards to compare what was done in the past months to what is done in current month.This is what i have come up with so far, however my _total is giving me ALL records in the table not this months records, so my percentages are off, aside from the _total the values it is calculating are correct.Can someone help me work through this.SELECT TransResult, COUNT(*) AS HowMany, (COUNT(*) / _total ) * 100 AS Percent FROM tbltranslog, (SELECT COUNT(*) AS _total FROM tbltranslog) AS myTotal WHERE MONTH(Date) = MONTH(NOW()) +0 GROUP BY transresultthanks. Quote Link to comment https://forums.phpfreaks.com/topic/31897-solved-calculating-a-based-on-date-range/ Share on other sites More sharing options...
fenway Posted December 27, 2006 Share Posted December 27, 2006 What is it that you want to represent? Quote Link to comment https://forums.phpfreaks.com/topic/31897-solved-calculating-a-based-on-date-range/#findComment-148369 Share on other sites More sharing options...
ericsante Posted December 28, 2006 Author Share Posted December 28, 2006 this is my final query that worked for meSELECT TransResult, COUNT(*) AS HowMany, (COUNT(*) / _total ) * 100 AS Percent FROM tbltranslog, (SELECT COUNT(*) AS _total FROM tbltranslog WHERE MONTH(Date) = MOD(MONTH(NOW()),12 + 1)) AS myTotal WHERE MONTH(Date) = MOD(MONTH(NOW()), 12 +1) GROUP BY transresult Quote Link to comment https://forums.phpfreaks.com/topic/31897-solved-calculating-a-based-on-date-range/#findComment-148631 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.