Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the other case, and what you appear to be doing is to show the trend of values across some period of time, even though a value may not be provided every day... So, you may have from Oct 1, 2011 to Dec 1, 2011 (or any other date range for that matter).</p> <p>You can easily SIMULATE an entire range of dates by using mysql variables and joining to ANY table (where I have "AnyOtherTableInYourDatabase") that has at least the number of days you would want to look back at. In the example for just the dates, I am starting with whatever the current date is, and running back say... 60 days. You could also change the "starting date" with something else and go back/forward as needed.</p> <pre><code>select JustDates.OneDate from ( SELECT @r:= date_add(@r, interval 1 day ) OneDate FROM (select @r := current_date()) vars, AnyOtherTableInYourDatabase limit 30 ) JustDates </code></pre> <p>Now, to get the most recent "reading", tack on a column via a select/from. THEN, re-join THAT result set to the original readings table to get the value in question</p> <pre><code>select PreQuery.OneDate, PreQuery.LatestReading, Y2.Value from ( select JustDates.OneDate, ( select max( YRT.Date ) from YourReadingsTable YRT where YRT.Date &lt;= JustDates.OneDate ) as LatestReading from (SELECT @r:= date_add(@r, interval 1 day ) OneDate FROM (select @r := current_date()) vars, AnyOtherTableInYourDatabase limit 30 ) JustDates ) PreQuery JOIN YourReadingsTable Y2 on PreQuery.LatestReading = Y2.Date </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload