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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:23:42+00:00 2026-06-14T00:23:42+00:00

I am trying to retrieve statistical data between December of the previous year and

  • 0

I am trying to retrieve statistical data between December of the previous year and November of the current year. The date column of my table has the data type of date.

The following SQL works fine with the obvious problem that it only works if the year is manually changed. How would one accomplish the same with a dynamically changing year for this time period?

SELECT date, SUM(numCalls) AS callTotal FROM callstats_callData
WHERE date BETWEEN '2011-12-01' AND '2012-11-01'
GROUP BY date ORDER BY date

The data is being retrieved from a MySQL table by PHP.

UPDATE

The code below works but I was hoping to have an SQL based solution.

$date1 = (date("Y") - 1) . '12-01';
$date2 = date("Y") . '-11-01';
$fetchTotals = $this->contentDB->prepare("SELECT date, SUM(numCalls) AS callTotal FROM callstats_callData
WHERE date BETWEEN ? AND ?
GROUP BY date ORDER BY date");
$fetchTotals->execute(array($date1, $date2));
$totals = $fetchTotals->fetchAll();

Working Example

This is to retrieve the call data for the Total Calls chart here. The results need to be retrieved in a loop in order to display the total for each month in that period of time. This page is currently working properly using the PHP & MySQL code above, just hoping for an SQL based solution.

  • 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-14T00:23:43+00:00Added an answer on June 14, 2026 at 12:23 am

    This gives you a bit of flexibility in selecting arbitrary month and day values for updated queries – as you set in your posted PHP code:

    SELECT date, SUM(numCalls) AS callTotal 
    FROM callstats_callData
    WHERE DATE(date) 
    BETWEEN CONCAT(YEAR(CURDATE())-1,'-12-01') AND CONCAT(YEAR(CURDATE()),'-11-01')
    GROUP BY date ORDER BY date;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to retrieve a column from another related table, and display that
Trying to retrieve related data from the relationships table, after user clicks on the
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I am trying to retrieve RSS feed using php. The xml has many different
I'm trying to retrieve a stored date in a MS Access 2003 database ..
trying to retrieve the id column of records that have their checkboxes selected in
I am trying to retrieve JSON formatted data from a remote domain (Zencoder video
i am trying to retrieve the data from the server with Linq ,there are
I'm trying to retrieve data that's put outside element blocks. Sample; <td> <b>abc</b> 123
I am trying retrieve data from a .php file on a server from within

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.