您现在的位置是:网站首页> 数据库

with as 进行表的树查询

摘要

查阅相关资料,对于数性表结构的数据,生成的SQ可参考以下代码实现,为避免排版出现混乱,增加必要的文字进行填充

SQLString = "with temp(sys_js_uuid,jsname,parentjs_uuid,sys_companys_nodeuuid,ischild)";

SQLString += " as ";

SQLString += "(";

SQLString += "select sys_js_uuid,jsname,parentjs_uuid,sys_companys_nodeuuid,ischild ";

SQLString += " from  sys_js ";

SQLString += " where parentjs_uuid=" + m_SessionLink.sys_js_uuid + " and ischild=1";

SQLString += " union all ";

SQLString += "select a.sys_js_uuid,a.jsname,a.parentjs_uuid,a.sys_companys_nodeuuid,a.ischild ";

SQLString += " from sys_js a ";

SQLString += " inner join temp on a.parentjs_uuid=temp.sys_js_uuid and a.ischild=1";

SQLString += ")";

SQLString += "select * from temp where sys_companys_nodeuuid=0 or sys_companys_nodeuuid=" + sys_companys_nodeuuid;


Top