Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8397873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:53:44+00:00 2026-06-09T20:53:44+00:00

I have a problem that I just cannot seem to get my head around,

  • 0

I have a problem that I just cannot seem to get my head around, and hope someone can help give me some advice.

Ever since getting solar PV cells fitted on my house roof, I have been generating electricity and in accordance to some (rather generous) incentives to do this kind of thing, have been making money for every kWh of electricity I generate. Seeing this as being a bit of a database project, I set about writing some PHP/MySQL to track daily generation, and now have nearly a year’s worth of daily kWh readings, which are nicely presented to me in graphical form, both in a month-by-month view, and as a yearly (grouped into months) graph.

I’m now wanting to expand the system to show revenue in monetary terms, rather than kWh of electricity. Currently, the figure is £0.454 per kWh, though this figure changes every year on the April 1st (it was £0.433 previously).

This is my current MySQL structure:

Table feedin:
  year (year4)   rate (float)
  2010           0.433
  2011           0.433
  2012           0.454

Table generation:
  day (DATE)     reading (float)
  2011-12-01     7.682
  2011-12-02     5.747
  2011-12-03     4.982
  ...            ...
  2012-08-13     8.022
  2012-08-14     19.449
  2012-08-15     5.484

My first attempt at this was all rather cumbersome with a very mixed mess of PHP and MySQL queries, with the bulk of the logic being done in PHP (my MySQL skills are “limited”, at best). However, as time is going on, I see that it would be ideal if the whole thing were done in MySQL.

I’ve no real idea how to tackle this. My initial thoughts are that we need to select yearly chunks of data (well, date-ranges from April 1st in one year, to March 31st the next), and multiply it by the appropriate year rate. And that “appropriate year rate is the rate applicable at the start of that date range, ie, as of April 1st).

Ideally, I’d like the query to be able to cope with multiple yearly boundaries, so, for example, several years down the road, I’d like to be able to query the absolute total revenue produced to date. Ultimately, I would just like to pass the query the start and end dates, and it returns the correct figure.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T20:53:45+00:00Added an answer on June 9, 2026 at 8:53 pm

    Link the year of the generation date to the year of the feedin tariff

    SELECT *, generation.reading*feedin.rate AS profit
     FROM generation, feedin
     WHERE YEAR(generation.day)=feedin.year
    

    BUT as this must relate to year start of APRIL 1st

    SELECT *, generation.reading*feedin.rate AS profit
     FROM generation, feedin
     WHERE YEAR(DATE_SUB(generation.day, INTERVAL 3 MONTH))=feedin.year
    

    This will move the recorded dates back 3 months too, making them Jan-Dec instead of Apr-Mar wich will then match the feedin year

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with an MVC view that I just cannot seem to
I've just installed VS2008 and have run into a problem that I'm sure can
I am having a problem that just started happening in OS 3.1. I have
I have a problem, i have a query that just simply displays the user
I have a viewController that autorotates just fine, The problem is that is I
I have a dynamic list code that works just fine. My only problem now
I have some problems with Javascript. In fact, I'm just newbie in that script
I have a problem that I'm working on for quite some time now. I
I'll just get right into it. I have a class User that needs to
Here's an interesting problem that I have just come across. It is possible to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.