包含下级的SQL语句请教?(20分)

  • 主题发起人 主题发起人 zgjob
  • 开始时间 开始时间
Z

zgjob

Unregistered / Unconfirmed
GUEST, unregistred user!
id &nbsp; mc &nbsp; &nbsp; &nbsp; prvid(0为一级)<br>1 &nbsp; &nbsp;内科 &nbsp; &nbsp; &nbsp; &nbsp; 0<br>2 &nbsp; &nbsp;外科 &nbsp; &nbsp; &nbsp; &nbsp; 0<br>3 &nbsp; &nbsp;内一科 &nbsp; &nbsp; &nbsp; 1<br>4 &nbsp; &nbsp;外一科 &nbsp; &nbsp; &nbsp; 2<br>5 &nbsp; &nbsp;内二科 &nbsp; &nbsp; &nbsp; 1<br>6 &nbsp; &nbsp;内一科(门) 3<br>.......<br>要求通过SQL语句求出已知的上级科室名称,求它的所有下级及名称.<br>如内科及内科下面的所有分级的名称<br>要求的结果如下:<br>id &nbsp; &nbsp;mc &nbsp; &nbsp; <br>1 &nbsp; &nbsp; 内科 &nbsp;<br>3 &nbsp; &nbsp; 内一科<br>5 &nbsp; &nbsp; 内二科<br>6 &nbsp; &nbsp; 内一科(门)
 
select id ,mc from table where mc like '内%'
 
Select * From Table Where Prvid In(<br>&nbsp; Select Prvid From Table Where mc=''<br>)
 
Select * From Table Where Prvid In(<br>&nbsp; Select id From Table Where mc=''<br>)
 

Similar threads

D
回复
0
查看
834
DelphiTeacher的专栏
D
后退
顶部