我的表有几个具有相同MemberID的记录.我想只得到一条记录.
select DISTINCT(MemberID) from AnnualFees;
然后结果会来.但我想显示其他列数据,但当我这样做
select DISTINCT(MemberID),StartingDate,ExpiryDate,Amount from AnnualFees;
有人能帮我吗.
假设你只想为每个memberid随机选择任何行,你可以这样做:
原文链接:https://www.f2er.com/oracle/205198.htmlselect memberid,this,that,theother from ( select memberid,theother,row_number() over (partition by memberid order by this) rn from annualfees ) where rn = 1;
如果您想要每个memberid的特定行,例如具有最新StartDate的那个然后您可以将其修改为:
select memberid,row_number() over (partition by memberid order by StartDate desc) rn from annualfees ) where rn = 1;