急求一个sql语句!! - MS-SQL Server / 基础类
有这样一个表,wy_yslb,字段有yslb_id,yslb_cname,yslb_parentid,yslb_class,yslb_mjflg.一个树形结构,yslb_mjflg = '1'即为最末级。
例如: yslb_id yslb_cname yslb_parentid yslb_class yslb_mjflg
1 A 0 1 0
2 BBB 0 1 0
3 a 1 2 0
4 aaa 3 3 1
5 b 2 2 1
现在给yslb_mjflg = '1' 的yslb,能用一个sql语句得到他的上级包括他本身吗?望指教下呵
SQL code:
--> 测试数据: #T1
if object_id('tempdb.dbo.#T1') is not null drop table #T1
create table #T1 (yslb_id int,yslb_cname varchar(3),yslb_parentid int,yslb_class int,yslb_mjflg int)
insert into #T1
select 1,'A',0,1,0 union all
select 2,'BBB',0,1,0 union all
select 3,'a',1,2,0 union all
select 4,'aaa',3,3,1 union all
select 5,'b',2,2,1
select * from #T1 where yslb_mjflg = '1'
union all
select * from #t1 where yslb_id in (select yslb_parentid from #T1 where yslb_mjflg = '1' )
yslb_id yslb_cname yslb_parentid yslb_class yslb_mjflg
----------- ---------- ------------- ----------- -----------
4 aaa 3 3 1
5
相关问答:
执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......
我想查询出每天数据的最大的一个值。表的格式如下
表名: hisdata
字段 编号 值 状态 时间
Id value state dattime
101 32.3 0 ......
需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......