beckwiga
Programmer
- Mar 30, 2005
- 70
Hello all! Not sure how I write my query to get the following... If you see the attached screen, you'll see that I occassionally am getting the same UPC twice because my Item Desc is slightly different (typos) so my Group By is generating 2 records. I want to use a Count (which I'm doing in this query) to count the number of stores that have the Item Desc one way, and count the number of stores that have it the other way, and then use the Item Desc that the majority of the Stores are using. So for example, you can see UPC 0000000000161 the Item Desc varies slightly. 51 Stores have it one way, the other 87 stores have it the other way. I want my query to return just the record for 0000000000161 where the Item Desc is "SUNK AW 7UP 20Z 2/3" (where there are more stores with this description).
Does this make sense? How do I structure my query to return just this Item Desc record? I imagine I have to do a subquery of some sort, maybe return TOP 1 ordering by Count(*) DESC or something?
Any help is much appreciated. Thanks!
This query gets the screen shot:
SELECT Product.[UPC Code], Product.[POS Modifier], Product.[Item Code], Product.[Item Desc], Product.[Dept Code], Product.[Cat Code], Product.[Pack Code], Count(*) AS "Count of Stores with Desc"
FROM Product
GROUP BY Product.[UPC Code], Product.[POS Modifier], Product.[Item Code], Product.[Item Desc], Product.[Dept Code], Product.[Cat Code], Product.[Pack Code];
Does this make sense? How do I structure my query to return just this Item Desc record? I imagine I have to do a subquery of some sort, maybe return TOP 1 ordering by Count(*) DESC or something?
Any help is much appreciated. Thanks!
This query gets the screen shot:
SELECT Product.[UPC Code], Product.[POS Modifier], Product.[Item Code], Product.[Item Desc], Product.[Dept Code], Product.[Cat Code], Product.[Pack Code], Count(*) AS "Count of Stores with Desc"
FROM Product
GROUP BY Product.[UPC Code], Product.[POS Modifier], Product.[Item Code], Product.[Item Desc], Product.[Dept Code], Product.[Cat Code], Product.[Pack Code];