MySql 对 over 子句使用正确的语法

发布于 2024-11-14 16:22:14 字数 237 浏览 8 评论 0原文

让 over 子句在 mysql 中工作的正确语法是什么?

我想查看每个用户发送的短信总数,而不用 group by 子句对其进行分组。

SELECT 
    username, 
    count(sentSmsId) OVER (userId) 
FROM 
    sentSmsTable,
    userTable
WHERE
    userId = sentUserId;

What is the correct syntax to get the over clause to work in mysql?

I would like to see the total sms's sent by each user without grouping it with the group by clause.

SELECT 
    username, 
    count(sentSmsId) OVER (userId) 
FROM 
    sentSmsTable,
    userTable
WHERE
    userId = sentUserId;

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

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

发布评论

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

评论(4

晌融 2024-11-21 16:22:14

MySQL 8 拥有窗口函数!因此,您可以在其中编写查询,如下所示:

SELECT username, 
       count(sentSmsId) OVER (partition by userId) 
FROM sentSmsTable
JOIN userTable ON userId = sentUserId;     

MySQL 8 has got the window functions! Therefore, you can write your query in it like this:

SELECT username, 
       count(sentSmsId) OVER (partition by userId) 
FROM sentSmsTable
JOIN userTable ON userId = sentUserId;     
热风软妹 2024-11-21 16:22:14

据我所知,MySQL 中没有 OVER 子句,但这里有一个链接可以帮助您实现相同的结果:

http://explainextend.com/2009/03/10/analytic-functions-first_value-last_value-lead-lag/

希望这会有所帮助。

There is no OVER clause in MySQL that I know of, but here is a link that might assist you to accomplish the same results:

http://explainextended.com/2009/03/10/analytic-functions-first_value-last_value-lead-lag/

Hope this helps.

唯憾梦倾城 2024-11-21 16:22:14

MySQL 目前不支持窗口函数,因此 over() 只会产生语法错误(或者垃圾,如果无论如何都接受的话)。

MySQL does not currently support window functions, so over() will only yield syntax errors (or garbage, if it's accepted regardless).

凯凯我们等你回来 2024-11-21 16:22:14

MySQL 直到最新版本:MySQL 8(2018 年 4 月发布)才具有窗口函数。 MS SQL Server 还接受 OVER 子句。

语法是:

function(col1) OVER (PARTITION BY col2 ORDER BY col3)

查看 https://mysqlserverteam.com/mysql -8-0-2-introducing-window-functions/ 了解更多示例。

MySQL Doesn't have window functions until the most recent release: MySQL 8 (release in April, 2018). MS SQL Server also accepts OVER clause.

The syntax is:

function(col1) OVER (PARTITION BY col2 ORDER BY col3)

Check out https://mysqlserverteam.com/mysql-8-0-2-introducing-window-functions/ for more examples.

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