MySql 对 over 子句使用正确的语法
让 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
MySQL 8 拥有窗口函数!因此,您可以在其中编写查询,如下所示:
MySQL 8 has got the window functions! Therefore, you can write your query in it like this:
据我所知,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.
MySQL 目前不支持窗口函数,因此 over() 只会产生语法错误(或者垃圾,如果无论如何都接受的话)。
MySQL does not currently support window functions, so
over()
will only yield syntax errors (or garbage, if it's accepted regardless).MySQL 直到最新版本:MySQL 8(2018 年 4 月发布)才具有窗口函数。 MS SQL Server 还接受 OVER 子句。
语法是:
查看 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:
Check out https://mysqlserverteam.com/mysql-8-0-2-introducing-window-functions/ for more examples.