最大值唯一

时间:2017-07-24 22:01:07

标签: sql sql-server tsql

有如下表格。如果最大confidenceCode值是唯一的,则返回该行,否则为否。

 LocationID ConfidenceCode
 017755029   05
 017755029   05
 017755029   01
 018577655   05
 018577655   09
 021886301   10
 021886301   09
 021886301   09           

预期产出

  LocationID ConfidenceCode
  018577655   09
  021886301   10

我的SQL如下,它正在工作,寻找更好的版本

 ;WITH CTEConfidenceCode as
 (
 SELECT *, dense_rank() over (partition by  LocationID order by 
 [ConfidenceCode] desc)  as ConfidenceRowNum FROM testTable
 ),
 CTEGroup as 
 (SELECT DUNS1,[ConfidenceCode],count(1) countValue  FROM CTEConfidenceCode
 WHERE ConfidenceRowNum=1
 GROUP BY LocationID,[ConfidenceCode])

 SELECT * FROM CTEGroup WHERE countValue=1

1 个答案:

答案 0 :(得分:1)

嗯。嗯。 。 。如果我理解你的问题:

[HttpPost]
[Route("Send")]
public HttpResponseMessage Send(MessageDetails details)
{

}

public class MessageDetails
{
    public string usernameTo { get; set; }
    public string message { get; set; }
}