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

  • Home
  • SEARCH
  • 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 8502003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:22:00+00:00 2026-06-11T01:22:00+00:00

Im having a mysql problem, I am trying to find the most current value

  • 0

Im having a mysql problem, I am trying to find the most current value for a specific month, the entire table schema and data can be seen here, the query that I have written to accomplish this is as follows:

max(case 
when Month(py.pay_date) = 8
then amount  end) previous_month_amount

However It is not returning the correct values, in this case the correct values should be:

name  previous_month_amount
Carl      30
Mark      40

Hope I made the question clear enough, and thank you for your help.

  • 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-11T01:22:01+00:00Added an answer on June 11, 2026 at 1:22 am

    I am interpreting your question as “What is the last payment made in each month?” If you answer this, then you can get the appropriate “last payment” just by choosing the right month. The following query does this:

    select p.name, lp.yr, lp.mon, pa.amount
    from persons p join
         (select person_id, year(pay_date) as yr, month(pay_date) as mon,
                 max(pay_date) as max_pay_date
          from payment
          group by person_id, year(pay_date), month(pay_date)
         ) lp
         on p.id = lp.person_id join
         payment pa
         on p.id = pa.person_id and
            pa.pay_date = lp.max_pay_date
    group by p.name, lp.yr, lp.mon, pa.amount
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a mysql problem I am trying to find both the most
I'm having trouble with MySQL or Python and can't seem to isolate the problem.
I´m trying to create a trigger on MySQL but I´m having a syntax problem,
I am having a big problem trying to connect to mysql. When I run:
I'm new to php and MySQL and I'm having a problem trying to work
I am trying to take data from one mysql table and insert it in
I'm having problem trying to access the MySQL server (I'd like to replace a
I'm having a little problem with trying to sort the contents of a table
I'm having a problem trying to truncate the 'requestID' field from my requests table.
I am trying to move from MySQL to MySQLi but am having some problems.

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.