当前位置: 代码迷 >> SQL >> sql 基础 四 树查询
  详细解决方案

sql 基础 四 树查询

热度:56   发布时间:2016-05-05 13:04:36.0
sql 基础 4 树查询
1、从叶子节点依据id=pid的关系向上递归到跟节点。select t.*, t.rowid from indicators t start with (t.isleaf='1' and t.rid='26020')connect by prior t.pid = t.id order by t.inum从跟节点依据id=pid的关系向下递归至叶子节点.select t.*, t.rowid from indicators t start with (t.pid='0' and t.rid='26020')connect by prior t.id = t.pid order by t.inum2、decode的用法 decode(条件,值1,返回值1,值2,返回值2,...值n,返回值n,缺省值)  [类似于 switch 语句] decode(字段或字段的运算,值1,值2,值3) [如果是 值1 ,返回值2,否则返回 值3] SELECT DECODE (value, <if this value>, <return this value>) FROM table_name 统计男女人数: select sum(decode(sex,'男',1,0)),sum(decode(sex,'女',1,0)) from table_name 
  相关解决方案