简体   繁体   English

每月给出每个行号-Oracle SQL

[英]Give out each row number per month - Oracle SQL

I have a table like this: 我有一张这样的桌子:

Month     | Date   
----------------------
May 2019  | 03.05.19
May 2019  | 04.05.19 
May 2019  | 07.05.19   
July 2019 | 03.07.19
July 2019 | 05.07.19 
July 2019 | 06.07.19  
July 2019 | 08.07.19 

And I wanna have a query that gives out the following. 我想要一个查询,给出以下内容。

Month     | Date    | Row Count per Month
----------------------
May 2019  | 03.05.19 | 1
May 2019  | 04.05.19 | 2
May 2019  | 07.05.19 | 3
July 2019 | 03.07.19 | 1
July 2019 | 05.07.19 | 2
July 2019 | 06.07.19 | 3
July 2019 | 08.07.19 | 4

So it gives out the number of each row per month but I don't know how to do it ( I have many more months and dates than those). 因此,它给出了每月每行的数量,但我不知道该怎么做(我的月份和日期比那多得多)。 I am trying to do it with row_number but can't seem to get it right. 我正在尝试使用row_number来执行此操作,但似乎无法正确执行。 Any tips? 有小费吗?

Use row_number() 使用row_number()

select *,row_number() over(partition by month order by date) as Row_Count
from tablename

使用row_number()

   select t.*, row_number() over( partition by month order by date) rn from table t

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM