我想按分区窗口函数将cat_id分组

发布于 2025-02-14 00:22:47 字数 236 浏览 2 评论 0原文

select row_number() over(partition by cat_id order by order_time desc) as row_num, order_id,location from order_table;

在此查询窗口函数中,有什么问题不在显示其错误运行查询的显示:您的SQL语法中有一个错误;检查与您的MySQL Server版本相对应的手册,以了解要使用的正确语法(分区。

select row_number() over(partition by cat_id order by order_time desc) as row_num, order_id,location from order_table;

Whats wrong in this Query Window function is not running Its showing Error running query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(partition by. Please can anyone help me here Breaking my head

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

季末如歌 2025-02-21 00:22:47

您的SQL代码似乎没有错。我使用以下版本“@8.0.28”对随机数据进行了测试。请检查您的版本完全支持这些功能。我

USE TEST;
CREATE TABLE order_table (order_id INT, cat_id INT, order_time DATETIME, location VARCHAR(50));
INSERT INTO order_table VALUES
(323412, 102, '2020-10-12 13:50:55', 'Seattle'),
(323413, 103, '2020-12-15 10:26:09', 'Kentucky'),
(323414, 104, '2020-05-03 23:34:12', 'Alabama'),
(323415, 103, '2020-06-07 16:40:23', 'Seattle'),
(323416, 104, '2020-11-19 12:20:54', 'Alabama'),
(323417, 102, '2020-12-20 11:40:15', 'Arizona'),
(323418, 103, '2020-04-26 14:33:37', 'Seattle'),
(323419, 104, '2020-02-12 10:21:23', 'Alabama'),
(323420, 102, '2020-09-23 09:31:21', 'California');

select row_number() over(partition by cat_id order by order_time desc) as row_num, order_id,location from order_table;

Result_set:
[Result_sets][1]

Nothing seems wrong with your sql code. I tested with random data below using the version '@8.0.28'. Please check your version is fully supporting these capabilities. I

USE TEST;
CREATE TABLE order_table (order_id INT, cat_id INT, order_time DATETIME, location VARCHAR(50));
INSERT INTO order_table VALUES
(323412, 102, '2020-10-12 13:50:55', 'Seattle'),
(323413, 103, '2020-12-15 10:26:09', 'Kentucky'),
(323414, 104, '2020-05-03 23:34:12', 'Alabama'),
(323415, 103, '2020-06-07 16:40:23', 'Seattle'),
(323416, 104, '2020-11-19 12:20:54', 'Alabama'),
(323417, 102, '2020-12-20 11:40:15', 'Arizona'),
(323418, 103, '2020-04-26 14:33:37', 'Seattle'),
(323419, 104, '2020-02-12 10:21:23', 'Alabama'),
(323420, 102, '2020-09-23 09:31:21', 'California');

select row_number() over(partition by cat_id order by order_time desc) as row_num, order_id,location from order_table;

Result_set:
[Result_sets][1]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文