Solved

Select DISTINCT(cust_nbr), MAX(cmplt_dt)

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
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…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

821 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