我有一个类似这样的查询
SELECT
t.category,
tc.product,
tc.sub-product,
count(*) as sales
FROM tg t, ttc tc
WHERE t.value = tc.value
GROUP BY t.category, tc.product, tc.sub-product;
Run Code Online (Sandbox Code Playgroud)
现在,在我的查询中,我想要获取每个类别的前 10 个产品(按销售额排名最高),并且对于每个类别,我需要前 5 个子类别(按销售额排名最高)
您可以将问题陈述假设为如下所示:
获取每个类别(按销售额)排名前 10 的产品,并针对每个产品获取按销售额排名前 5 名的子产品。
输入数据格式示例
category |product |subproduct |Sales [count (*)]
abc test1 test11 120
abc test1 test11 100
abc test1 test11 10
abc test1 test11 10
abc test1 test11 10
abc test1 test11 10
abc test1 test12 10
abc test1 test13 8
abc test1 test14 6
abc …Run Code Online (Sandbox Code Playgroud) 我正在尝试了解抽象数据类型"序列",并告诉它有排名和位置.Rank是指在给定元素之前的元素数量,但是它的位置是什么?
说我有一些SELECT陈述:
SELECT id, name FROM people
ORDER BY name ASC;
Run Code Online (Sandbox Code Playgroud)
我在people表中有几百万行,该ORDER BY子句可能比我在这里显示的要复杂得多(可能在十几列上运行).
我只检索行的一小部分(比如行1..11),以便在UI中显示它们.现在,我想解决以下问题:
id.id.一旦我解决了问题1,问题2很容易解决,因为如果我知道我要查找的项目1000在排序结果集中有行号(这是Firebird SQL方言),我就可以使用这样的东西:
SELECT id, name FROM people
ORDER BY name ASC
ROWS 995 TO 1005;
Run Code Online (Sandbox Code Playgroud)
我也知道,我能找到的等级通过计算所有一个我找前落入排了一排,但是这可能会导致很长的WHERE从句用吨OR和AND在状态.我必须反复这样做.使用我的测试数据,即使使用正确索引的列,这也需要数百毫秒,这太慢了.
是否有一些方法可以通过使用一些SQL:2003功能(如row_numberFirebird 3.0支持)来实现这一目的?我绝不是一个SQL大师,我需要一些指针.我可以创建一个缓存视图,其结果将包括排名/密集排名/行索引?
我想知道如何在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编写的?)
我需要在 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)
除了子图不显示外,一切都完美无缺。一旦在集群外定义了等级,子图就会消失。

如果在簇体内部定义,则簇之间的相同等级将丢失。
我在 SQL Server 中有一个这样的表 -
ID Employee_id group_field_code from_date To_date
================================================================================
1 44855 055 2015-04-01 00:00:00 2015-04-02 17:37:26
2 44855 055 2015-04-02 17:37:27 2015-04-25 09:31:10
3 44855 055 2015-04-25 09:31:11 2015-09-18 14:58:59
4 44855 053 2015-09-18 15:00:00 2016-04-02 02:58:59
5 44855 055 2016-04-02 03:00:00 2016-05-26 02:58:59
6 44855 055 2016-05-25 13:25:23 2016-09-07 14:58:59
7 44855 055 2016-05-26 03:00:00 2016-05-25 13:25:22
8 44855 052 2016-09-07 15:00:00 2017-05-22 02:58:59
9 44855 055 2017-05-22 03:00:00 NULL
Run Code Online (Sandbox Code Playgroud)
我想要的只是当组字段更改时一行的新排名。就像-对于ID 1-3(group_code 55)我想要一个排名,对于ID 4(group_Code更改,53)我想要另一个排名,然后对于ID 5(group_code 5重新到达)我想要另一个排名,依此类推。在 SQL …
我对 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) 我有一个矩阵 A = np.array([[1,1,1],[1,2,3],[4,4,4]]) 我只想要新矩阵中的线性独立行。答案可能是 A_new = np.array([1,1,1],[1,2,3]]) 或 A_new = np.array([1,2,3],[4,4,4])
由于我有一个非常大的矩阵,所以我需要将矩阵分解为更小的线性独立满秩矩阵。有人可以帮忙吗?
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) rank ×10
sql ×5
mysql ×2
python ×2
sql-order-by ×2
sql-server ×2
alignment ×1
firebird ×1
fortran ×1
graphviz ×1
matrix ×1
oracle ×1
pandas ×1
position ×1
python-3.x ×1
row-number ×1
rowcount ×1
sequences ×1
subgraph ×1