TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Lynn Emery
NA
47
56.3k
Select Where Maximum
Mar 6 2013 6:24 AM
Hi I am trying to create an SQL view in Visual studio.
I want to filter out results to show the maximum sales for each customer based on each month and year and to display a description of the sales
I have the following statement:
SELECT Customer, Month, Year, sales, Description
FROM dbo.salestable
GROUP BY Customer, Month, Year, sales, Description
HAVING (sales =
(SELECT MAX(dbo.salestable.ppm) AS Expr1))
This doesn't seem to be working as I get duplicates for each month rather than one entry for each customer per month which should be the maximum sales for that customer.
I think the group by is causing an issue but it forces me to group each field.
Hopefully there is a simple solution?
Thank you for your help in advance.
Reply
Answers (
1
)
selecting and Grouping data
How to Delete duplicate record from table in sql server 2008