Solved

Select DISTINCT(cust_nbr), MAX(cmplt_dt)

Posted on 2006-10-26
3
420 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

680 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