篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql MS SQL数据聚合 - ROW_NUMBER相关的知识,希望对你有一定的参考价值。
SELECT ROW_NUMBER() OVER(ORDER BY name ASC) AS RowNum,
name,
recovery_model_desc
FROM sys.databases
WHERE database_id < 5;
-- [Output]
-- RowNum name recovery_model_desc
-- 1 master SIMPLE
-- 2 model FULL
-- 3 msdb SIMPLE
-- 4 tempdb SIMPLE
-- Adding a PARTITION BY value_exp clause, will
-- restart the numbering when the value_exp value changes.
SELECT ROW_NUMBER() OVER(
Partition BY recovery_model_desc
ORDER BY name ASC) AS RowNum,
name,
recovery_model_desc
FROM sys.databases
WHERE database_id < 5;
-- [Output]
-- RowNum name recovery_model_desc
-- 1 master SIMPLE
-- 1 model FULL
-- 2 msdb SIMPLE
-- 3 tempdb SIMPLE
以上是关于sql MS SQL数据聚合 - ROW_NUMBER的主要内容,如果未能解决你的问题,请参考以下文章