Hi All, I have a table that has records for commission splits on products -- one record for each person involved in the product and his split Product Person Split 123 100 50 123 101 50 124 102 72 124 101 28 I need to product a report and pick out the person with the largest split, so for product 124 its a no brainer. But for product 123, I just need an arbitrary selection, but only one, and I don't care which one. I'm joining this table with my product master file on product id. Thanks in advance. Richard Mogy
Rich - There are a couple ways to do this, but I like the following approach (you could also do a self-join): select top 1 y.product, y.person, y.split from yourTable y where split = (select max(y2.split) from yourTable y2 where y2.product = y.product) [quoted text, click to view] "Rich Mogy" <rmogy@sbcglobal.net> wrote in message news:aVQLf.35104$Jd.25841@newssvr25.news.prodigy.net... > Hi All, > I have a table that has records for commission splits on products -- one > record for each person involved in the product and his split > > Product Person Split > 123 100 50 > 123 101 50 > 124 102 72 > 124 101 28 > > I need to product a report and pick out the person with the largest split, > so for product 124 its a no brainer. But for product 123, I just need an > arbitrary selection, but only one, and I don't care which one. I'm > joining this table with my product master file on product id. > > Thanks in advance. > > Richard Mogy >
Thanks for the input. I'll try it. [quoted text, click to view] "VC" <me@here.com> wrote in message news:LsOdnXSv6JZL0J7ZnZ2dnUVZ_sCdnZ2d@comcast.com... > Rich - There are a couple ways to do this, but I like the following > approach (you could also do a self-join): > > select top 1 y.product, y.person, y.split > from yourTable y > where split = (select max(y2.split) from yourTable y2 where y2.product = > y.product) > > > "Rich Mogy" <rmogy@sbcglobal.net> wrote in message > news:aVQLf.35104$Jd.25841@newssvr25.news.prodigy.net... >> Hi All, >> I have a table that has records for commission splits on products -- one >> record for each person involved in the product and his split >> >> Product Person Split >> 123 100 50 >> 123 101 50 >> 124 102 72 >> 124 101 28 >> >> I need to product a report and pick out the person with the largest >> split, so for product 124 its a no brainer. But for product 123, I just >> need an arbitrary selection, but only one, and I don't care which one. >> I'm joining this table with my product master file on product id. >> >> Thanks in advance. >> >> Richard Mogy >> > >
Thanks -- it is far more elegant than what I did.... [quoted text, click to view] "VC" <me@here.com> wrote in message news:LsOdnXSv6JZL0J7ZnZ2dnUVZ_sCdnZ2d@comcast.com... > Rich - There are a couple ways to do this, but I like the following > approach (you could also do a self-join): > > select top 1 y.product, y.person, y.split > from yourTable y > where split = (select max(y2.split) from yourTable y2 where y2.product = > y.product) > > > "Rich Mogy" <rmogy@sbcglobal.net> wrote in message > news:aVQLf.35104$Jd.25841@newssvr25.news.prodigy.net... >> Hi All, >> I have a table that has records for commission splits on products -- one >> record for each person involved in the product and his split >> >> Product Person Split >> 123 100 50 >> 123 101 50 >> 124 102 72 >> 124 101 28 >> >> I need to product a report and pick out the person with the largest >> split, so for product 124 its a no brainer. But for product 123, I just >> need an arbitrary selection, but only one, and I don't care which one. >> I'm joining this table with my product master file on product id. >> >> Thanks in advance. >> >> Richard Mogy >> > >
I spoke too soon -- the SQL, as written only produces one row -- I need one row for each product. [quoted text, click to view] "Rich Mogy" <rmogy@sbcglobal.net> wrote in message news:jyMMf.40997$H71.18523@newssvr13.news.prodigy.com... > Thanks for the input. I'll try it. > "VC" <me@here.com> wrote in message > news:LsOdnXSv6JZL0J7ZnZ2dnUVZ_sCdnZ2d@comcast.com... >> Rich - There are a couple ways to do this, but I like the following >> approach (you could also do a self-join): >> >> select top 1 y.product, y.person, y.split >> from yourTable y >> where split = (select max(y2.split) from yourTable y2 where y2.product = >> y.product) >> >> >> "Rich Mogy" <rmogy@sbcglobal.net> wrote in message >> news:aVQLf.35104$Jd.25841@newssvr25.news.prodigy.net... >>> Hi All, >>> I have a table that has records for commission splits on products -- one >>> record for each person involved in the product and his split >>> >>> Product Person Split >>> 123 100 50 >>> 123 101 50 >>> 124 102 72 >>> 124 101 28 >>> >>> I need to product a report and pick out the person with the largest >>> split, so for product 124 its a no brainer. But for product 123, I just >>> need an arbitrary selection, but only one, and I don't care which one. >>> I'm joining this table with my product master file on product id. >>> >>> Thanks in advance. >>> >>> Richard Mogy >>> >> >> > >
select y.product, y.person, y.split from testing1 y where y.split = (select max(y2.split) from testing1 y2 where y2.product = y.product) and y.person = (select top 1 person from testing1 y3 where y3.split = y.split) [quoted text, click to view] "Rich Mogy" <rmogy@sbcglobal.net> wrote in message news:nq%Mf.38280$F_3.22621@newssvr29.news.prodigy.net... > Thanks -- it is far more elegant than what I did.... > "VC" <me@here.com> wrote in message > news:LsOdnXSv6JZL0J7ZnZ2dnUVZ_sCdnZ2d@comcast.com... >> Rich - There are a couple ways to do this, but I like the following >> approach (you could also do a self-join): >> >> select top 1 y.product, y.person, y.split >> from yourTable y >> where split = (select max(y2.split) from yourTable y2 where y2.product = >> y.product) >> >> >> "Rich Mogy" <rmogy@sbcglobal.net> wrote in message >> news:aVQLf.35104$Jd.25841@newssvr25.news.prodigy.net... >>> Hi All, >>> I have a table that has records for commission splits on products -- one >>> record for each person involved in the product and his split >>> >>> Product Person Split >>> 123 100 50 >>> 123 101 50 >>> 124 102 72 >>> 124 101 28 >>> >>> I need to product a report and pick out the person with the largest >>> split, so for product 124 its a no brainer. But for product 123, I just >>> need an arbitrary selection, but only one, and I don't care which one. >>> I'm joining this table with my product master file on product id. >>> >>> Thanks in advance. >>> >>> Richard Mogy >>> >> >> > >
Still only one line. [quoted text, click to view] "VC" <me@here.com> wrote in message news:S7mdnTSar-vqN5jZnZ2dnUVZ_v2dnZ2d@comcast.com... > select y.product, y.person, y.split > from testing1 y > where > y.split = (select max(y2.split) from testing1 y2 where y2.product = > y.product) > and y.person = (select top 1 person from testing1 y3 where y3.split = > y.split) > > "Rich Mogy" <rmogy@sbcglobal.net> wrote in message > news:nq%Mf.38280$F_3.22621@newssvr29.news.prodigy.net... >> Thanks -- it is far more elegant than what I did.... >> "VC" <me@here.com> wrote in message >> news:LsOdnXSv6JZL0J7ZnZ2dnUVZ_sCdnZ2d@comcast.com... >>> Rich - There are a couple ways to do this, but I like the following >>> approach (you could also do a self-join): >>> >>> select top 1 y.product, y.person, y.split >>> from yourTable y >>> where split = (select max(y2.split) from yourTable y2 where y2.product = >>> y.product) >>> >>> >>> "Rich Mogy" <rmogy@sbcglobal.net> wrote in message >>> news:aVQLf.35104$Jd.25841@newssvr25.news.prodigy.net... >>>> Hi All, >>>> I have a table that has records for commission splits on products -- >>>> one record for each person involved in the product and his split >>>> >>>> Product Person Split >>>> 123 100 50 >>>> 123 101 50 >>>> 124 102 72 >>>> 124 101 28 >>>> >>>> I need to product a report and pick out the person with the largest >>>> split, so for product 124 its a no brainer. But for product 123, I >>>> just need an arbitrary selection, but only one, and I don't care which >>>> one. I'm joining this table with my product master file on product id. >>>> >>>> Thanks in advance. >>>> >>>> Richard Mogy >>>> >>> >>> >> >> > >
Don't see what you're looking for? Try a search.
|