memsql真的支持排名功能吗?

时间:2016-03-16 06:54:15

标签: sql window-functions memsql

http://docs.memsql.com/5.0/concepts/window_functions/

我检查了上面链接的文档,并提出了几个可能的SQL函数,但没有任何运气。这些只是几个:

select row_number() from test;
select row_number() over (order by _id) from test;
select row_number() over {order by _id} from test;
select row_number() over order by _id from test;
select row_number() over (order by _id) as row_num from test;
select row_number over order by _id as row_num from test;

所有给我ERROR 1064(42000):你的SQL语法有错误;

MemSQL版本是5.5.8

当然select _id from test;工作正常吗?

那么使用的确切语法是什么?或者在MemSQL中实际上没有这样的东西?

1 个答案:

答案 0 :(得分:3)

你看到的版本字符串是一个mysql兼容版本,我假设你做的是SELECT version();。要正确检查MemSQL版本,请使用SHOW VARIABLES WHERE Variable_name = 'memsql_version';

窗口函数是MemSQL 5中的新功能,让我相信你没有运行MemSQL 5.这并不奇怪,因为5仍处于测试阶段(截至2016-03-16)。您可以获得测试版here

在回答你的问题时,dnoeth正确地指出查询#2和#5是有效的。为了尽职调查,我针对本地构建的MemSQL运行了这些查询,并且两者都有效。

memsql> create table test(_id int);
Query OK, 0 rows affected (0.01 sec)

memsql> insert into test values (1), (2), (3);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

memsql> select row_number() over (order by _id) from test;
+----------------------------------+
| row_number() over (order by _id) |
+----------------------------------+
|                                1 |
|                                2 |
|                                3 |
+----------------------------------+
3 rows in set (0.00 sec)

memsql> select row_number() over (order by _id) as row_num from test;
+---------+
| row_num |
+---------+
|       1 |
|       2 |
|       3 |
+---------+
3 rows in set (0.01 sec)

memsql> SHOW VARIABLES WHERE Variable_name = 'memsql_version';
+----------------+-------+
| Variable_name  | Value |
+----------------+-------+
| memsql_version | 5.0   |
+----------------+-------+
1 row in set (0.00 sec)