Robert Stearns wrote:
I want a table with a single row for each animal along with one owner,
independent of the number of owners, 0, 1, or more. In the case that
more than one owner for a particular animal exists I would like the
owner with the largest percentage, if there is one. When the percentages
are equal (50/50., etc.), any of the owners will do. If there was not
the requirement that there only be one row per animal a LEFT OUTER JOIN
ON animals.bhid=owners.bhid would suffice.
Can you do something like:
select
bhid
,location
,entity_id
,percent
from (
select
a.bhid
,a.location
,o.entity_id
,o.percent
,rownumber() over (partition by o.bhid
order by o.percent desc) as owner_rank
from
animals a
left outer join owners o
on a.bhid=o.bhid
) as x
where
owner_rank = 1;
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----