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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:43:43+00:00 2026-05-15T13:43:43+00:00

I am wanting to do some queries on a sales table and a purchases

  • 0

I am wanting to do some queries on a sales table and a purchases table, things like showing the total costs, or total sales of a particular item etc.

Both of these tables also have a date field, which stores dates in sortable format(just the default I suppose?)

I am wondering how I would do things with this date field as part of my query to use date ranges such as:

The last year, from any given date of the year

The last 30 days, from any given day

To show set months, such as January, Febuary etc.

Are these types of queries possible just using a DATE field, or would it be easier to store months and years as separate tex fields?

  • 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-15T13:43:43+00:00Added an answer on May 15, 2026 at 1:43 pm

    If a given DATE field MY_DATE, you can perform those 3 operation using various date functions:

    1. Select last years records

    SELECT * FROM MY_TABLE
    WHERE YEAR(my_date) = YEAR(CURDATE()) - 1
    

    2. Last 30 Days

    SELECT * FROM MY_TABLE
    WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) < MY_DATE
    

    3. Show the month name

    SELECT MONTHNAME(MY_DATE), * FROM MY_TABLE
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm wanting to save some OpenId fields to a database table, such as OpenId
I am processing my website and wanting to change some things on the pages.
I was just wanting some explanation as to what is going on once you
I used to use the implicit call of toString when wanting some debug info
I am wanting to expose some data service endpoints for internal application use and
I am wanting to send some data to a server from a client application
Lately, I've often found myself wanting to run some command on the output of
Wanting to implement authentication by client certificates I am experiencing some issues. First some
I am wanting to store the state of some actions the user is performing
I'm wanting to run AJAX to get some URL data, build an object from

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.