如何根据条件从重复集中显示单行?

时间:2013-10-09 21:55:09

标签: sql

acquisitionID    Logno.             FundName
1               2                   Allocated
1               2                   Potential
2              34                   Allocated
3              37                   Potential
4              40                   Allocated
4              40                   Potential
5              39                   Potential

我想只显示那些有FundName为Allocated的行,如果有两个基金,即(Allocated / Potential),否则我想按原样显示它。即。

acquisitionID   Logno.               FundName
1               2                   Allocated
2               34                  Allocated
3               37                  Potential
4               40                  Allocated
5               39                  Potential   

1 个答案:

答案 0 :(得分:1)

SELECT AcquisitionID, [LogNo.], min(FundName)
FROM myTable 
GROUP BY AcquisitionID, [LogNo.]