June 29, 2015 at 12:40 pm
Hi,
I wanted to find the max value of a column. I have the following table structure
OrderIDTaskIDSerialNo
112
123
211
222
From the above table i want the following result for every orderID and TaskID display the max value
SerialNo
2
3
1
2
By using MAX i am getting the OrderID and TaskID as well which is not my intended result. I am using SQL Server. How would i get the intended result?
Thanks,
Rajagopalan
June 29, 2015 at 12:49 pm
What's your expected result?
June 29, 2015 at 12:55 pm
rajagopalanseeth (6/29/2015)
Hi,I wanted to find the max value of a column. I have the following table structure
OrderIDTaskIDSerialNo
112
123
211
222
From the above table i want the following result for every orderID and TaskID display the max value
SerialNo
2
3
1
2
By using MAX i am getting the OrderID and TaskID as well which is not my intended result. I am using SQL Server. How would i get the intended result?
Thanks,
Rajagopalan
Sounds like you're looking for something like this:
SELECT OrderID, TaskID, MAX(SerialNo)
FROM yourTable
GROUP BY OrderID, TaskID
ORDER BY OrderID, TaskID
Remove OrderID and/or TaskID from the SELECT if you don't want them displayed, but leave them in the GROUP BY.
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
July 1, 2015 at 1:48 am
you can try below this query :
SELECT OrderId, TaskID, MAX(SerialNo)SerialNo
FROM table_name
GROUP BY OrderId, TaskId
_______________________________________________________________
To get quick answer follow this link:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
July 1, 2015 at 7:18 am
kapil_kk (7/1/2015)
you can try below this query :
SELECT OrderId, TaskID, MAX(SerialNo)SerialNo
FROM table_name
GROUP BY OrderId, TaskId
Isn't that what I already said?
For best practices on asking questions, please read the following article: Forum Etiquette: How to post data/code on a forum to get the best help[/url]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply