Solved

Select DISTINCT(cust_nbr), MAX(cmplt_dt)

Posted on 2006-10-26
3
419 Views
Last Modified: 2013-11-30
Select DISTINCT(cust_nbr), MAX(cmplt_dt)
FROM sales_datebook, ui_results_db.emp1
where  cust_nbr IS NOT NULL
AND cmplt_dt > '05/14/2006'  
AND emp_nbr = emp1
group by cust_nbr, cmplt_dt

XXXXXXX      5/24/2006
XXXXXXX      6/29/2006
XXXXXXX      7/12/2006
XXXXXXX      8/25/2006
XXXXXXX      8/31/2006
XXXXXXX      10/2/2006
XXXXXXX      10/6/2006
XXXXXXX      10/17/2006

The above query results in the above list, which is the correct list.
However, my need is for only the LAST or LATEST date that the account was called, not all dates.
The DISTRICT() and MAX() seem to have no effect...+
Can someone help? Thanks!!!~bat
0
Comment
Question by:ba_trainer
3 Comments
 
LVL 9

Accepted Solution

by:
gpompe earned 500 total points
ID: 17813010
Try this:

Select cust_nbr, MAX(cmplt_dt)
FROM sales_datebook, ui_results_db.emp1
where  cust_nbr IS NOT NULL
AND cmplt_dt > '05/14/2006'  
AND emp_nbr = emp1
group by cust_nbr
0
 
LVL 8

Expert Comment

by:srafi78
ID: 17813014
Select cust_nbr, cmplt_dt
FROM sales_datebook, ui_results_db.emp1
where  cust_nbr IS NOT NULL
AND cmplt_dt > '05/14/2006'  
AND emp_nbr = emp1
AND cmplt_dt = (Select Max(cmplt_dt) from
sales_datebook, ui_results_db.emp1
where  cust_nbr IS NOT NULL
AND cmplt_dt > '05/14/2006'  
AND emp_nbr = emp1)
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 17813021
SELECT Cust_nbr, Max(cmplt_dt)cmplt_dt
FROM (
Select DISTINCT(cust_nbr), MAX(cmplt_dt) cmplt_dt
FROM sales_datebook, ui_results_db.emp1
where  cust_nbr IS NOT NULL
AND cmplt_dt > '05/14/2006'  
AND emp_nbr = emp1
group by cust_nbr, cmplt_dt
)T
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how the fundamental information of how to create a table.

839 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