我在读这个问题如何确定的类型?。正确的答案是,SELECT查询可以以SELECT或WITH开头。
为了供参考,答案说:
// SELECT subqueries are irrelevant for the final result. So the command, the first verb is indicative of the result (int updateCount vs. ResultSet).
boolean isSqlSelect = sql.toUpperCase().startsWith("SELECT")
|| sql.toUpperCase().startsWith("WITH");所以,现在让我们说我有一个查询
SELECT id, name, email FROM users;问题
WITH开头的查询?发布于 2020-07-28 19:01:09
WITH是公共表表达式 (CTE)的语法。这是所有合理数据库基本上都支持的标准SQL语法(MySQL是最后添加这种支持的)。
CTE用于定义可以在查询中多次引用的子查询。
请注意,CTE可以与UPDATE和DELETE语句以及SELECT一起使用,因此它们不一定表示SELECT。
发布于 2020-07-28 19:14:33
因为您还询问了如何使用CTE重写查询..。
with cte as
(select id, name, email
from users)
select * from cte;我发现在with子句的早期定义列名比较干净,所以我为select节省了一些空间。
with cte (id, name, email) as
(select *
from users)
select * from cte;https://stackoverflow.com/questions/63140925
复制相似问题