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 7864929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:56:08+00:00 2026-06-02T23:56:08+00:00

In my model I have the following query which average $probe values hour by

  • 0

In my model I have the following query which average $probe values hour by our for the last day available in the database.

$connection=Yii::app()->db;
$command=$connection->createCommand("SELECT AVG($probe), TIME FROM tbl_sensors GROUP BY DATE(TIME), HOUR(TIME) ORDER BY ID DESC LIMIT 0, 24");
$dataReader=$command->query();

Now I’d like to modify this query to get the result for yesterday, the day before yesterday etc.

My first thought was to add a variable fed by the controller modify LIMIT parameters. Though the following:

SELECT AVG($probe), TIME FROM tbl_sensors GROUP BY DATE(TIME), HOUR(TIME) ORDER BY ID DESC LIMIT 24, 48

returns 48 values instead of 24. I don’t understand why is that?

Any pointers welcome

  • 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-02T23:56:10+00:00Added an answer on June 2, 2026 at 11:56 pm

    LIMIT 24, 48 doesn’t mean from 24 to 48. it means from 24 to (24+48).
    if I say in another way, it starts from 24, get 48 records .

    LIMIT 24, 24
    

    http://dev.mysql.com/doc/refman/5.1/en/select.html

    but I recommend you to use WHERE

    SELECT AVG($probe), TIME FROM tbl_sensors
    WHERE `TIME` BETWEEN ... AND ...
    GROUP BY DATE(TIME), HOUR(TIME)
    ORDER BY ID DESC LIMIT 0, 24  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following Django Model which retrieves 3 records from a database. The
I have the following model class Plugin(models.Model): name = models.CharField(max_length=50) # more fields which
I have the following filter query which is doing an SQL OR statement: results
I have the following view model to query my table: QuestionViewModel.cs public enum TypeQuestion
I have the following queries which calculates the total order sale happened in last
In our database, we have the following tables Tags Id (int) Name (string) IsActive
I have following models setup in my Django application class School(models.Model): name = models.TextField()
I'm developing application using backbone.js & jquery. I have following code in model: runReport:
I have the following Model pattern: public abstract class PARENTCLASS {...} public class CHILD_A_CLASS
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)

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.