Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jpiscit1
Posting Yak Master
130 Posts |
Posted - 2004-04-02 : 14:06:00
|
| I have a query that sums defects by item number. As follows:Select Sum(low_lip)as [Low lip], item_no as [Item No]From prod_dataGroup By item_noThis produces something like:Low lip Item No2231 ISI0094A0 1 ISI03200 ISI00960 ISI006824 ISI03010 ISI0172B0 ISI03110 ISIOO74E22 ISI02919 D-5019 ISI0236D1 ISI0100B249 ISI0027I modified the query so that I can find out which item number is producing the most defects, as such:Select max(d.[Low lip]) as [lowlip]From(Select Sum(low_lip)as [Low lip], item_no as [Item No]From prod_dataGroup By item_no) dOrder by [lowlip] descWith the result set above this will produce:lowlip2231how can I modify this query so that it would give the same results but also include the Item no? For example, the result I want is:lowlip Item No2231 ISI0094AUltimately showing me which item no had the most defects...Thanks in advance. |
|
|
drymchaser
Aged Yak Warrior
552 Posts |
Posted - 2004-04-02 : 14:44:34
|
Here goes:SELECT TOP 1 [Low lip], [item no]FROM (Select Sum(low_lip)as [Low lip], item_no as [Item No]From prod_dataGroup By item_no) xORDER BY [low lip] DESC |
 |
|
|
jpiscit1
Posting Yak Master
130 Posts |
Posted - 2004-04-02 : 15:49:46
|
| Great thanks ! That worked |
 |
|
|
|
|
|