sql WITH关键字

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql WITH关键字相关的知识,希望对你有一定的参考价值。

\!h COUNT query embedded into a WITH statement (creates a temporary table)
WITH previous_query AS (
SELECT customer_id,
COUNT(subscription_id) as subscriptions
FROM orders
GROUP BY customer_id)

\!h A column from the previous query joined with a column from a separate table
SELECT customers.customer_name, 
previous_query.subscriptions
FROM previous_query
JOIN customers
ON customers.customer_id = previous_query.customer_id;

以上是关于sql WITH关键字的主要内容,如果未能解决你的问题,请参考以下文章

为啥这不起作用:使用 "With ROW_NUMBER" 插入 SQL 语句。错误是关键字“With”附近的语法不正确

在 Spark 中执行以“WITH”关键字开头的 SQL 语句

sqlserver 2008 with 关键字怎么用

在 SQL Server 中结合 CTE“WITH”和“WITH XMLNAMESPACES....”

sql server 2005 with如何实现递归

SQL中使用WITH 语句的查询