Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在SQLLite中对相同数据进行排序_Sql_Sqlite - Fatal编程技术网

在SQLLite中对相同数据进行排序

在SQLLite中对相同数据进行排序,sql,sqlite,Sql,Sqlite,我有如下表格 CREATE TABLE test( ID INT ); 有以下数据 我需要以下结果 ID Rank 100 1 100 2 105 1 105 2 105 3 我只需要使用普通的SQL查询,没有特殊的函数可以在相关查询中使用,以实现结果。因为rowid唯一地标识为row,所以我们可以在本例中使用它进行相关计数以分配行号 试试这个: select id, ( select count(*) from test t2

我有如下表格

CREATE TABLE test(
   ID INT
);
有以下数据

我需要以下结果

ID    Rank
100   1
100   2
105   1
105   2
105   3
我只需要使用普通的SQL查询,没有特殊的函数

可以在相关查询中使用,以实现结果。因为rowid唯一地标识为row,所以我们可以在本例中使用它进行相关计数以分配行号

试试这个:

select id, (
        select count(*)
        from test t2
        where t.id = t2.id
            and t2.rowid <= t.rowid
        ) rank
from test t;
您可以在相关查询中使用以获得结果。因为rowid唯一地标识为row,所以我们可以在本例中使用它进行相关计数以分配行号

试试这个:

select id, (
        select count(*)
        from test t2
        where t.id = t2.id
            and t2.rowid <= t.rowid
        ) rank
from test t;

为什么没有特殊函数?我只能看到SQL Lite中支持的函数为什么没有特殊函数?我只能看到SQL Lite中支持的函数你能解释你的答案吗?你能解释你的答案吗?