- For individual users
- Instant access to solutions
- Ask your tech questions
- Start your 30-day Free Trial
Main Topics
Browse All TopicsI have a few locations that I take the temperature of every day at noon. They are fairly consistent and each day will be the same as the previous day for the most part. What's the best way to set up the database to keep track of each day and then get the daily average for the month?
I could just do have an entry for every day, but I am looking to increase the number of locations. I could easily get to several thousand. Since the majority of the days will be the same, could I just input the date and the temperature on days where it does not match the previous day? If I had day 1, 15, and 29, that would mean day 1 through 14 were the same, 15 through 28 were the same, and 29-31 were the same.
Doing it that way may save space, but I don't know how I would actually get the daily average. The major problem would be figuring out how many days are in the month. Then I would have to figure out how many days were at each temperature. I don't think I could do all that in one SQL query. Is the amount of space I give up worth it to make the computing easier?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Business Accounts
Answer for Membership
by: angelIIIPosted on 2007-08-26 at 22:08:48ID: 19773781
>could I just input the date and the temperature on days where it does not match the previous day?
efman/5.0/ en/insert- on- duplica te.html
no, that will make the average calculations very difficult.
>how many days are in the month.
you can compute easily the last day of the month, by getting the first of next month and substract 1 day.
in mysql, there is even easier.
nevertheless, you can do this:
set up a trigger on the table, which adds the value to a total for the month in another table, and also increases the counter by 1.
the average will then simply be the total/counter, for that month.
the SQL hint to be given is the INSERT ... ON DUPLICATE KEY:
http://dev.mysql.com/doc/r
so, you try to INSERT a row with the year/month/location info, which is the key, and if it exists, you can update the existing row...