I have a device which reads kw values off electrical devices to measure their (rate of consumption of energy) at a certain time. these values are then sent to a poller (which periodically asks the device for the values), and inserted into a database.

Example:

```

1st reading - 10 kw at 1.01pm
2nd reading - 15 kw at 1.23pm
3rd reading - 11 kw at 1.30pm

```

As you can see, the polling interval is not fixed, so the values can be inserted into the database at different times. for simplicity, we can just imagine the database is just a table with 2 columns, [time] and [kw\_value].

This is actually a two part question:

1. How do I get the daily kwh value from these readings (energy consumption for the whole day)? I'm pretty bad in mathematics so I dont know what is the right way to get a daily kwh value from these values.

I thought of adding up all the values and getting the average, but my mom says that I should plot out a graph of all readings for the whole day, and then get the area below the plotted line (sort of like getting the integral of the graph), which will then give me the total power consumed for the day. I should then use this value to divide by the duration for the whole day in hours to get the kwh, is that right?
2. How do I do this using the database? if there are thousands of readings in a day (from multiple electrical devices,in this case we have 3 columns - [time],[kw\_value],[deviceid]), how should I calculate this, should I load up all the values in memory (i'm using C#) and calculate from there or can I use SQL to calculate this?

Edit:
Thanks guys for pointing out the difference between kw and kwh. i made a big mistake with my original question, hence this edit. just to reiterate, the device reads kw values (rate of energy consumption in kilo joules/sec) at a particular time, and given a list / plot of these values in the database, what's the correct way to determine the kwh (total energy consumed) for a given day.