I'm trying to adjust the below script to charge specific rates between certain hours during the day.

Mid-peak rate 7:00am - 11:00am cost is 11.4 cents/kwh

On-peak rate 11:00am - 5:00pm cost is 14 cents/kwh

Mid-peak rate 5:00pm - 7:00pm cost is 11.4 cents/kwh

Off-peak rate 7:00pm - 7:00am cost is 7.7 cents/kwh

SELECT M.NAME as 'Machine', FORMAT(SUM(MDU.HOURS), 0) as 'Hours On',FORMAT((COUNT(MDU.ID)*24) - SUM(MDU.HOURS),0) as 'Hours Off', FORMAT(SUM(MDU.HOURS) / COUNT(MDU.ID),0) as 'Avg Hours Per Day', CONCAT('$',FORMAT(SUM(MDU.HOURS) * .07 * .31, 2)) as 'Energy Cost Spent',
CONCAT('$', FORMAT(((COUNT(MDU.ID)*24) - SUM(MDU.HOURS)) *.07 * .31, 2)) as 'Energy Cost Saved'
FROM MACHINE M, MACHINE_DAILY_UPTIME MDU
WHERE MDU.MACHINE_ID = M.ID
AND MDU.DAY >= DATE_SUB(NOW(), INTERVAL 2 WEEK )
GROUP BY M.NAME


Does anyone know if this is possible?

Thanks

Matt



0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

0
The MACHINE_DAILY_UPTIME table doesn't track which hours the machine was on, just how many, because of that you can't calculate which of the hours it was in use. In order to break out costs by time interval you need data on when machines were actually powered on and powered off, not just the total hours they were powered on.
Answered 04/23/2015 by: chucksteel
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity
Admin Script Editor
Admin Script Editor is an integrated scripting environment available free here at ITNinja

Share