SELECT tblIssue.SYMB, tblIssue.[PRCE], tblIssue.[Shareholder]
FROM tblIssue
I am trying to pull the symb and price for the maximum number of shareholder per symb. For example, I would have only 1 line for ASN where the price would be $60.62.
SYMB Price Shareholder ASN $0.00 0 ASN $0.00 51 ASN $25.18 0 ASN $25.26 0 ASN $36.00 0 ASN $60.62 231 ASNL $0.00 101 ASR $0.00 4 ASR $0.00 24 ASR $37.17 13
This is similar to Quassnoi's answer but corrected to get the row with max Shareholder which is what the OP asked. If you have multiple rows for the same symbol with the same number of maximum shareholders, it would give you one of them at random. If you want them all, change ROW_NUMBER to RANK.
This should produce:
If that's what you are looking for.
In Oracle:
This is a trick I use with these sorts of problems: show me the row corresponding to
i1
when there is no other rowi2
with the same[SYMB]
and a greater[Shareholder]
. I.e. if no row with a greater[Shareholder]
exists, theni1
must have the greatest value.This query returns multiple rows when there's a tie for the highest
[Shareholder]
value per distinct value of[SYMB]
, but the same is true for most of the other answers given by other people on this thread. To solve this, you have to add another condition to the join using a unique column of the table.A correlated subquery seems the easiest (if I understand your problem):
which produces:
That would help;