473,382 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Getting Last payment information

Hi,

Let's say I have a table containing payment information:

CustID, PaymentDate, PaymentAmount. Here is some sample data:


CustID Date Amount
01 01/01/07 50.00
01 02/01/07 100.00
01 12/31/06 275.00

I'm interested in the last payment date and the amount paid on that last payment date. Is there a quick/easy way to do this?

Thanks,

Keith
Jan 30 '07 #1
4 2087
ronverdonk
4,258 Expert 4TB
Just sort it. Thanks to your funny date format you have to sort the date using the substr() function.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM test 
  2.   WHERE client=1
  3.   ORDER BY 
  4.     SUBSTR(date,7,2) DESC, 
  5.     SUBSTR(date,4,2) DESC, 
  6.     SUBSTR(date,1,2) DESC 
  7. LIMIT 1;
Ronald :cool:
Jan 30 '07 #2
Just sort it. Thanks to your funny date format you have to sort the date using the substr() function.
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM test 
  2.   WHERE client=1
  3.   ORDER BY 
  4.     SUBSTR(date,7,2) DESC, 
  5.     SUBSTR(date,4,2) DESC, 
  6.     SUBSTR(date,1,2) DESC 
  7. LIMIT 1;
Ronald :cool:

Thanks for your reply. I should have included more detail.

Let's say I have the customer list below:

01 John
02 Tom
03 Paul

And I have them making the following payments (Date formatting is unimportant)

01 03/12/06 $100.00
03 04/14/06 $42.50
03 12/31/06 $12.75
01 01/01/06 $167.00

I want a query that will show me the latest payment and payment amount for each Customer and return the following result set:

01 John 03/12/06 $100.00
02 Tom Null Null
03 Paul 12/31/06 $12.75

Thanks again for any help.

Keith
Jan 30 '07 #3
Motoma
3,237 Expert 2GB
Thanks for your reply. I should have included more detail.

Let's say I have the customer list below:

01 John
02 Tom
03 Paul

And I have them making the following payments (Date formatting is unimportant)

01 03/12/06 $100.00
03 04/14/06 $42.50
03 12/31/06 $12.75
01 01/01/06 $167.00

I want a query that will show me the latest payment and payment amount for each Customer and return the following result set:

01 John 03/12/06 $100.00
02 Tom Null Null
03 Paul 12/31/06 $12.75

Thanks again for any help.

Keith
What version of MySQL are you using?
Jan 30 '07 #4
What version of MySQL are you using?

Version 5.0.27 -community-nt via TCP/IP
Jan 30 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Robert Brown | last post by:
Hi All, I am creating an interface into a Payment Gateway. I need to access a URL (which is a perl script) with paramters attached. I will then get a response within 10 seconds with information...
2
by: Paul H | last post by:
My customer has an ecommerce store. He receives approx 600 orders per month. Worldpay.com handles the credit card transactions and sends my customer an email for each order containing the...
4
by: New Guy | last post by:
I'm trying to work with a system that somebody else built and I am confounded by the following problem: There is a table of payments and a table of charges. Each client has charges and payments...
0
by: TSD 2006 | last post by:
********************************************************* TSD 2006 - CALL FOR PARTICIPATION ********************************************************* Ninth International Conference on TEXT,...
3
by: rlbSQL | last post by:
I am trying to find the last payment date made to a vendor in a table. This table has many vendors I will need to have a line for each vendor and what thier last payment date is. I assume it...
1
by: myemail.an | last post by:
Hi all, I am a novice to Access, and was wondering if I could get some help on a problem I can't solve. I have a database with customer payments, structured like this: customer code type of...
2
by: scott | last post by:
Hi Everyone, I have a table which has many fields in it but I need to pull some specific info via a query and I don't know if it's possible. I want to run a query which includes two tables....
8
by: gnewsgroup | last post by:
I have never done anything involving handling credit card payment online. I searched this forum a little bit, and found a few related questions. But, I am still not clear how the solutions they...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.