Solved

Select DISTINCT(cust_nbr), MAX(cmplt_dt)

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
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.
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 SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now