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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:40:02+00:00 2026-05-21T07:40:02+00:00

My application has users entering records into a database. The records contain an auto-incrementing

  • 0

My application has users entering records into a database. The records contain an auto-incrementing id, date (as text in mm-dd-yyyy format), a quantity (int) and a few other fields.

I’m trying to grab all the months and the sum quantity for each month. So that I can display them in my app like: Dec 2010 – 90qty, Jan 2011 – 45qty…

What I’m doing now is, selecting date by id, ascending limit 1 and descending limit 1 to get the first and last dates in the database. I then split the months and year and calculate how many months are in there, then I do a for loop and fill an array so I have 12-2010, 01-2011, 02-2011…etc then another for loop to query the database for sum(quantity) where date is between 12-01-2011 and 12-31-2011, etc.

I’m wondering… is there a better way?

  • 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-05-21T07:40:02+00:00Added an answer on May 21, 2026 at 7:40 am
    CREATE TABLE test (
    id integer primary key, date date, quantity integer);
    INSERT INTO "test" VALUES(1,'2011-01-01',5);
    INSERT INTO "test" VALUES(2,'2011-02-01',13);
    INSERT INTO "test" VALUES(3,'2011-02-12',14);
    INSERT INTO "test" VALUES(4,'2011-03-01',133);
    

    You can group by months and sum up the quantities like this.

    select strftime('%Y-%m', date), sum(quantity) 
    from test
    group by strftime('%Y-%m', date);
    
    2011-01    5
    2011-02   27
    2011-03  133
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application database has a Groups table that separates users into logical roles and
Problem Overview: My application has an enrollment form. Users have a habit of entering
Take for example an application which has users, each of which can be in
Hi Sitepoint wizard people, Say we have an admin application that has multiple users
My current backbone application has a url: localhost/#users Is there a way to access
I am currently working on an application that has different permissions/users for the local
Say my application has a list of items of some kind, and users can
I have an application which has a Projects table and a Users table. In
I have a rails application that has three different types of users and I
We have a web application that has custom errors turned on so that users

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.