如何在SQLite的更新/删除中使用CTE?

编程入门 行业动态 更新时间:2024-10-27 22:32:09
本文介绍了如何在SQLite的更新/删除中使用CTE?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

SQLite现在具有CTE,并且文档表示您可以将其与插入,更新和删除查询一起使用-但

SQLite now has CTEs, and the documentation says you can use it with insert, update and delete queries -- but only gives examples of select statements.

我可以通过insert-select找出CTE如何应用于插入。但是如何在没有从句的情况下如何在更新或删除中使用它们?

I can figure out how CTEs apply to inserts, via insert-select; but how can we use them in update or delete, where there is no from-clause?

推荐答案

CTE可以在子查询中使用:

CTEs can be used in subqueries:

WITH NewNames(ID, Name) AS (...) UPDATE MyTable SET Name = (SELECT Name FROM NewNames WHERE ID = MyTable.ID); WITH IDsToDelete AS (...) DELETE FROM MyTable WHERE ID IN IDsToDelete;

更多推荐

如何在SQLite的更新/删除中使用CTE?

本文发布于:2023-10-24 08:20:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   SQLite   CTE

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!