MySQL“与"条款 [英] MySQL "WITH" clause

查看:38
本文介绍了MySQL“与"条款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MySQL 创建带有WITH"子句的视图

I'm trying to use MySQL to create a view with the "WITH" clause

WITH authorRating(aname, rating) AS
   SELECT aname, AVG(quantity)
   FROM book
   GROUP BY aname

但是 MySQL 好像不支持这个.

But it doesn't seem like MySQL supports this.

我认为这是非常标准的,而且我确信 Oracle 支持这一点.有没有强制 MySQL 使用WITH"子句?我已经用 MyISAM 和 innoDB 引擎试过了.这两个都不起作用.

I thought this was pretty standard and I'm sure Oracle supports this. Is there anyway to force MySQL to use the "WITH" clause? I've tried it with the MyISAM and innoDB engine. Both of these don't work.

推荐答案

更新:MySQL 8.0 终于获得了公共表表达式的特性,包括递归 CTE.

Update: MySQL 8.0 is finally getting the feature of common table expressions, including recursive CTEs.

这是一个宣布它的博客:http://mysqlserverteam.com/mysql-8-0-labs-recursive-common-table-expressions-in-mysql-ctes/

Here's a blog announcing it: http://mysqlserverteam.com/mysql-8-0-labs-recursive-common-table-expressions-in-mysql-ctes/

以下是我之前的回答,最初是在 2008 年写的.

Below is my earlier answer, which I originally wrote in 2008.

MySQL 5.x 不支持使用 SQL-99 中定义的 WITH 语法的查询,也称为通用表表达式.

MySQL 5.x does not support queries using the WITH syntax defined in SQL-99, also called Common Table Expressions.

自 2006 年 1 月以来,这是 MySQL 的功能请求:http://bugs.mysql.com/bug.php?id=16244

This has been a feature request for MySQL since January 2006: http://bugs.mysql.com/bug.php?id=16244

其他支持公用表表达式的 RDBMS 产品:

Other RDBMS products that support common table expressions:

这篇关于MySQL“与"条款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆