sql server with as只能查询一次
WITH Emp AS (SELECT acc.* FROM GXSpreadDB.dbo.gxs_account acc LEFT JOIN RYAccountsDB.dbo.AccountsInfo Account ON acc.userid=Account.userid WHERE parentuserid=7123 AND Account.AgentID=0 UNION ALL SELECT d.* FROM Emp ,GXSpreadDB.dbo.gxs_account d WHERE d.parentuserid =Emp.userid ), DaiLi_RelationalTree AS ( select * from GXSpreadDB.dbo.gxs_account where gameid=208356 ) --select * from DaiLi_RelationalTree select * from Emp,DaiLi_RelationalTree
以上代码是没问题的。
这个代码就会报对象不存在。可能要插入到临时表才能重复查询吧
WITH Emp AS (SELECT acc.* FROM GXSpreadDB.dbo.gxs_account acc LEFT JOIN RYAccountsDB.dbo.AccountsInfo Account ON acc.userid=Account.userid WHERE parentuserid=7123 AND Account.AgentID=0 UNION ALL SELECT d.* FROM Emp ,GXSpreadDB.dbo.gxs_account d WHERE d.parentuserid =Emp.userid ), DaiLi_RelationalTree AS ( select * from GXSpreadDB.dbo.gxs_account where gameid=208356 ) select * from DaiLi_RelationalTree select * from Emp,DaiLi_RelationalTree
本文来自博客园,作者:沉迷编程的程序员,转载请注明原文链接:https://www.cnblogs.com/codeDevotee/p/11349978.html
欢迎各位找我代写程序,python、c#、web等都可以,加我请注明博客园微信:A15919195482
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步