一张表table有以下字段(id,名称,parentid)满足 parentid 是0 的就是父类否则是子类
id name parentid
1 aaa 0
2 bbb 1
3 vvv 1
4 ddd 5
5 jjj 0
6 kkk 5
使用的是连接查询left join 要求显示的是一下效果:
id name childname
1 aaa bbb
2 aaa vvv
3 jjj ddd
4 jjj kkk
id name parentid
1 aaa 0
2 bbb 1
3 vvv 1
4 ddd 5
5 jjj 0
6 kkk 5
使用的是连接查询left join 要求显示的是一下效果:
id name childname
1 aaa bbb
2 aaa vvv
3 jjj ddd
4 jjj kkk
解决方案 »
- LINQ获取的实体类 FLOAT类型的属性总是报null空引用异常,hlep,hlep,help,help,help,help
- 数据库函数问题。
- {"Fill: SelectCommand.Connection 属性尚未初始化。"}
- 有每有生成16位随机字串的现成函数??
- 如何在一个用户控件里调用另一个用户控件的方法?
- 20分~请问asp.net如何掉用js文件里的function??
- 新手问题:为什么ACCESS数据库中插不进STRING类型的数据?
- ::URL跳转时,如何保持当前URL地址不变::
- 怎么用javascript实现选中treeview的某个结点
- 小妹请教一个关于SQL2005的问题
- asp.net301设置的代码放在哪里都错误呢
- 一个ASP.net MVC的问题,关于action的。
select parent.id, parent.name, child.name as childname
from table as child
left join table as parent
where child.parentid <> 0
and child.parentid = parent.id
from table c left join table p
on c.parentid = p.id
where c.parentid>0
select parent.id, parent.name, child.name as childname
from table as child
left join table as parent
on child.parentid = parent.id
where child.parentid <> 0
from table c left join table a
on c.parentid=a.id where c.parentid>0
into #temp from table as parent left join table as child
on child.parentid = parent.id
where parent.parentid = 0 order by parent.id select * from #temp