我有一张类似这样的表:
User ID creation_time Clicked Rank
2.30417E+13 10:39:03 AM FALSE 1
2.30417E+13 10:40:35 AM TRUE 1
2.30417E+13 10:40:36 AM TRUE 2
2.30417E+13 10:40:50 AM FALSE 1
2.30417E+13 10:41:20 AM TRUE 1
2.30417E+13 10:41:36 AM TRUE 2
2.30417E+13 10:42:41 AM TRUE 3
2.30417E+13 10:42:41 AM TRUE 4
2.30417E+13 10:44:23 AM TRUE 5
2.30417E+13 10:44:34 AM TRUE 6
2.30417E+13 10:44:36 AM TRUE 7
2.30417E+13 10:44:39 AM TRUE 8
2.30417E+13 10:44:44 AM TRUE 9
2.30417E+13 10:44:50 AM TRUE 10
2.30417E+13 10:44:53 AM TRUE 11
2.30417E+13 10:44:56 AM TRUE 12
2.30417E+13 10:45:05 AM TRUE 13
2.30417E+13 10:45:40 AM FALSE 1
2.30417E+13 10:45:41 AM TRUE 1
2.30417E+13 10:46:07 AM TRUE 2
2.30417E+13 10:46:07 AM TRUE 3
2.30417E+13 10:46:08 AM TRUE 4
排名列是我想如何对行进行排名。在表中我有数百个用户,我想根据他完成的点击次数/没有点击次数对每个用户进行排名。 任何的想法?我已经尝试过rank,row_number,它们的不同设置..无法弄明白。
答案 0 :(得分:0)
您需要<div id="divRepwithHeader" runat="server">
<div id="divHeader" runat="server" class="DivHdr" style="text-align: center; width: 100%;
border: 1px;">
<asp:Label ID="litCompanyName" runat="server" Font-Size="Medium" Font-Bold="True"></asp:Label><br />
<asp:Label ID="litCompanyAdd" runat="server" Font-Italic="True"></asp:Label><br /><br />
<asp:Label ID="litRepTitle" runat="server" Font-Size="Medium" Font-Bold="True"></asp:Label>
</div>
<br />
<table runat="server" id="tableExtras" width="100%" class="printTable" summary="headers">
<tr runat="server">
<th style="width: 50%">Bank Account</th>
<th style="width: 20%">Entry Date</th>
<th style="width: 15%">Fiscal Year</th>
<th style="width: 15%">Month</th>
</tr>
</table><br />
<table runat="server" id="tableReportBank" class="printTableBRS" width="100%" /><br />
<table runat="server" id="tableReportCash" class="printTableBRS" width="100%" /></div>
的分组列。这可以计算为用户ID和单击列的值的运行总和,其中单击为false。
所以:
row_number()
有时,亚马逊需要窗口函数的窗口子句,因此您可能需要select t.*,
row_number() over (partition by userid, clicked, grp order by creation_time) as rank
from (select t.*,
sum(case when clicked = false then 1 else 0 end) over (partition by userid order by creation_time) as grp
from t
) t;
。 Postgres没有这个要求。