[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

SQL - Determine Last Customer Sales

Posted on 2013-01-24
4
Medium Priority
?
463 Views
Last Modified: 2013-01-24
Stuck on stupid again...

I need to set up an SQL statement to yield the date of the last sales invoice by date. For some reason this morning, I can't seem to wrap head around it.

Here's what I'm trying to do:

Let's say I have a customer table with the Customer Number, the Invoice Date and the Invoice Amount as follows:

Cust      Date       Amount
A      05/01/12       $5.00
A      07/15/12       $17.25
A      08/30/12       $18.24
B      04/02/12       $25.00
B      07/13/12       $27.00
B      09/25/12       $84.00
C      03/13/12       $23.00
C      04/17/12       $19.00
C      12/21/12       $16.00

I need to run an SQL statement to yield the following result:

Cust      Date
A      08/30/12
B      09/25/12
C      12/21/12

I'd appreciate the assistance to get me past this.
Thanks,
Todd
0
Comment
Question by:shambalad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 61

Accepted Solution

by:
mbizup earned 1600 total points
ID: 38815058
SELECT Cust, Max([Date]) as MostRecent
FROM YourTable
GROUP BY Cust

Open in new window

0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 400 total points
ID: 38815063
select A.* from
sales as A
Inner join
(select max(b.date) as maxdate, b.cust
  from sales as b
  group by b.cust
) as C
on a.date=c.maxdate and a.cust=c.cust
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38815068
And if you need additional fields...

SELECT * 
FROM YourTable t INNER JOIN
(SELECT Cust, Max([Date]) as MostRecent
FROM YourTable
GROUP BY Cust) q
ON q.MostRecent = t.[Date]

Open in new window

0
 
LVL 7

Author Closing Comment

by:shambalad
ID: 38815221
Splitting the points. Thanks again.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question