Jump to content

[SOLVED] Calculating a % based on date range


ericsante

Recommended Posts

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 transresult

thanks.
Link to comment
https://forums.phpfreaks.com/topic/31897-solved-calculating-a-based-on-date-range/
Share on other sites

this is my final query that worked for me

SELECT 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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.