SQLserver中取众位数的写法
Posted 闲汉
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQLserver中取众位数的写法相关的知识,希望对你有一定的参考价值。
取众位数:先按个数倒排序,再取第一条
SELECT * FROM
(
select a.billid,a.DemandVoltage,count(1) as RecordCount,
Row_NUMBER() OVER(PARTITION BY billid ORDER BY count(1) DESC) AS SN
from ETL_SingleCharging201805 a with(nolock)
WHERE RowKey LIKE \'00000058-bca0-4559-8f8f-2fc3b61eb01c%\'
OR Rowkey LIKE \'000001b7-3e26-47fd-9a67-b177750d5147%\'
group by a.billid,a.DemandVoltage
) b
WHERE b.billid IN (\'00000058-bca0-4559-8f8f-2fc3b61eb01c\',
\'000001b7-3e26-47fd-9a67-b177750d5147\') AND b.SN=1
按个数排序:
select a.billid,a.DemandVoltage,count(1) as RecordCount, Row_NUMBER() OVER(PARTITION BY billid ORDER BY count(1) DESC) AS SN
from ETL_SingleCharging201805 a with(nolock)
WHERE RowKey LIKE \'00000058-bca0-4559-8f8f-2fc3b61eb01c%\' OR Rowkey LIKE \'000001b7-3e26-47fd-9a67-b177750d5147%\'
group by a.billid,a.DemandVoltage
以上是关于SQLserver中取众位数的写法的主要内容,如果未能解决你的问题,请参考以下文章