我正在尝试了解抽象数据类型"序列",并告诉它有排名和位置.Rank是指在给定元素之前的元素数量,但是它的位置是什么?
我正在使用Symfony 1.4和Doctrine 1.2 ORM构建应用程序.我对ORM的学说很新,并且我已经掌握了它,但我无法解决这个问题.
我有一个用户分数表(mbScoreByGenre),其中一个用户ID可以有一个parent_genre的多个用户分数记录.即 - 很多甚至很多
我的目标是根据给定parent_genre_id和user_id的累积分数查找特定用户的排名.我的排名算法使用子查询,我在构建一个有效的学说查询时遇到了很多麻烦.
这是我对mbScoreByGenre的学说模式
mbScoreByGenre:
actAs:
Timestampable: ~
columns:
id: { type: integer, primary: true, autoincrement: true }
user_id: { type: integer, notnull: true }
genre_id: { type: integer, notnull: true }
parent_genre_id: { type: integer, notnull: true }
score: { type: float, notnull: true, default: 0 }
Run Code Online (Sandbox Code Playgroud)
A.首先我尝试做这样的事情:
$q = Doctrine_Query::create()
->select('((SELECT COUNT(1) AS num
FROM
(SELECT SUM(mbScoreByGenre.score)
WHERE SUM(mbScoreByGenre.score) > SUM(s.score)
AND mbScoreByGenre.parent_genre_id = '.$genre['parent_id'].'
AND s.parent_genre_id = '.$genre['parent_id'].'
GROUP BY mbScoreByGenre.user_id
) …
Run Code Online (Sandbox Code Playgroud) 我想知道如何在Fortran中最好地处理一个带有未知等级参数的子程序.例如:
Real * 8 :: array1(2,2),array2(2,2,3)
call mysubroutine(array1)
call mysubroutine(array2)
Run Code Online (Sandbox Code Playgroud)
至于现在,我总是需要修复子程序中的形状(等级数).
例如,内在子程序random_number(array)可以做到.(但也许它不是用Fortran编写的?)
例如,在数据库(SQL Server)中,一列值如下:
Col1
====
10
5
15
20
5
10
2
Run Code Online (Sandbox Code Playgroud)
这就像整数数据列表.
排名应该是:
Col1 Rank
==== ====
20 1
15 2
10 3
10 3
5 4
5 4
2 5
Run Code Online (Sandbox Code Playgroud)
我试过以下方式:
1) First sort the list of data in descending order of "Col1" value
2) Find the index of a particular record using FindIndex() method.
3) Then Rank = Index + 1
Run Code Online (Sandbox Code Playgroud)
但它只有在数据是唯一的情况下才有效.当索引返回时,当多个行中存在相同的"Col1"值时,它会失败0, 1, 2, 3, 4, 5, 6
.
如何使用C#LINQ列出包含不同的数据(在大多数情况下!)时的排名?
我有一个数据框如下.最初只有两列/变量 - "Timestamp"(包含日期和时间)和"Actor".我将"时间戳"变量分解为"日期"和"时间",然后将"时间进一步分解为"小时"和"分钟".然后给出以下结构
dataf<-structure(list(hours = structure(c(3L, 4L, 4L, 3L, 3L, 3L, 6L,
6L, 6L, 6L, 6L, 2L, 2L, 2L, 2L, 5L, 5L, 5L, 1L, 1L, 2L, 2L), .Label = c("9",
"12", "14", "15", "16", "17"), class = "factor"), mins = structure(c(17L,
1L, 2L, 14L, 15L, 16L, 3L, 4L, 6L, 6L, 7L, 9L, 9L, 13L, 13L,
10L, 11L, 12L, 2L, 5L, 8L, 8L), .Label = c("00", "04", "08",
"09", "10", "12", "13", "18", "19", "20", "21", "22", "27", "39",
"51", "52", …
Run Code Online (Sandbox Code Playgroud) 我需要在 MySQL 中对行进行排序并根据该顺序为每一行分配一个数字。ORDER BY
正在按预期工作,但不是ROW_NUMBER()
。
这有效:
USE my_database;
SELECT
id
,volume
FROM my_table
ORDER BY volume;
Run Code Online (Sandbox Code Playgroud)
这不起作用:
USE my_database;
SELECT
id
,volume
,ROW_NUMBER() over(ORDER BY volume)
FROM my_table
ORDER BY volume;
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
SELECT id ,volume ,ROW_NUMBER() over(ORDER BY volume) FROM my_table ORDER BY volume 错误代码:1064。您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 4 行 0.000 秒处的“(ORDER BY volume) FROM my_table ORDER BY vol”附近使用的正确语法
我做错了什么,我该如何使它工作?
我也试过RANK()
,DENSE_RANK()
这给出了同样的问题。
我有以下代码:
digraph G {
bgcolor=antiquewhite;
compound=true;
{
rankdir=LR ;
rank=same g0 p1 p2 p3 h1;
}
subgraph cluster0 {
style=filled;
color=khaki;
g0 [label="G",shape=circle,style="filled", color="red", fillcolor="lightpink"]
label = "Cluster 0";
g0 -> p1;
}
subgraph cluster1 {
style=filled;
color=khaki;
p1 [label="S2",shape=box,style="filled", color="blue", fillcolor="skyblue"];
p2 [label="S3",shape=box,style="filled", color="blue", fillcolor="skyblue"];
p3 [label="S3",shape=box,style="filled", color="blue", fillcolor="skyblue"];
label = "Cluster 1";
p1 -> p2 -> p3 [arrowhead=none] ;
}
subgraph cluster2 {
style=filled;
color=khaki;
h1 [label="h1",shape=box,style="invis"];
label = "Cluster 2";
p3 -> h1;
}
}
Run Code Online (Sandbox Code Playgroud)
除了子图不显示外,一切都完美无缺。一旦在集群外定义了等级,子图就会消失。
如果在簇体内部定义,则簇之间的相同等级将丢失。
我试图在一个小组内获得正确的排名,并且结果有问题.我需要在每次基于时间戳更改组时获得排名.
例如,使用此表:
create table syntrans (
transid number,
launchtime timestamp,
status varchar2(10)
);
insert into syntrans values ( 1, '19-APR-17 07.34.05.824875 PM','FAIL');
insert into syntrans values ( 1, '19-APR-17 07.34.06.828753 PM','FAIL');
insert into syntrans values ( 1, '19-APR-17 07.34.08.567579 PM','SUCCESS');
insert into syntrans values ( 1, '19-APR-17 08.07.31.731745 PM','SUCCESS');
insert into syntrans values ( 1, '19-APR-17 08.07.32.735582 PM','SUCCESS');
insert into syntrans values ( 2, '19-APR-17 08.17.51.332804 PM','FAIL');
insert into syntrans values ( 2, '19-APR-17 08.17.52.336530 PM','FAIL');
insert into syntrans values …
Run Code Online (Sandbox Code Playgroud) 我对 Python 中的排名很好奇。输出如何到达,如下所示?排名对数据有什么影响?
Input obj = pd.Series([7,-5,7,4,2,0,4])
Run Code Online (Sandbox Code Playgroud)
输出:
print(obj)
0 7
1 -5
2 7
3 4
4 2
5 0
6 4
Run Code Online (Sandbox Code Playgroud)
秩
print(obj.rank())
0 6.5
1 1.0
2 6.5
3 4.5
4 3.0
5 2.0
6 4.5
Run Code Online (Sandbox Code Playgroud) I want to rank on ID and value columns based on ascending order of UID. Expected output has to change once value column has a different value than the previous value. Ranks has to restart on each new ID
UID ID Value Expected Output
1 1 0 1
2 1 0 1
3 1 1 2
4 1 1 2
5 1 1 2
6 1 0 3
7 1 1 4
8 1 0 5
9 1 0 5 …
Run Code Online (Sandbox Code Playgroud)