I’ve got a table thats just three columns, ID, DATETIME, VALUE
Each DATETIME is from various samples during the day, from different meters.
I need to perform a math function on each value eg. (value * 60 * 10)/1000000 = new_value, and then group new_value by DATE(datetime), and sum the values for each date, and do this for a select group of ID’s.
The result I need is each DATE, with its sum value of those meters.
I’ve tried:
SELECT date(sub_meter_data.date) as date,
sum(CASE WHEN sub_meterID = '58984' OR '58985' OR '58986' OR '58987' THEN (((value*60)*10)/1000000) ELSE 0 END) as value
FROM `sub_meter_data` WHERE
date(sub_meter_data.date) > '2012-10-01'
GROUP BY date(sub_meter_data.date)
Here’s some sample data:
sub_meterID date value
58984 2012-10-18 23:23:05.000 94.82643
58982 2012-10-18 23:28:52.000 97.43638
58984 2012-10-18 23:33:04.000 100.1923
58985 2012-10-18 23:43:01.000 97.93111
58984 2012-10-18 23:53:05.000 93.02759
58986 2012-10-19 00:03:03.000 88.29563
58984 2012-10-19 00:13:02.000 81.23074
58987 2012-10-19 00:23:07.000 86.37943
58984 2012-10-19 00:33:04.000 88.64834
Please try below: