一个关于case查询的语句,问题已详细描述,望各位指教
表k_webclass如下
+-----+------------+------+
| id | cname | up |
+-----+------------+------+
| 1 | class1 | 0 |
+-----+------------+------+
| 2 | class2 | 0 |
+-----+------------+------+
| 3 | class3 | 1 |
+-----+------------+------+
| 4 | class4 | 3 |
+-----+------------+------+
| 5 | class5 | 2 |
+-----+------------+------+
想要的查询结果如下
+-----+------------+------+
| id | cname | up |
+-----+------------+------+
| 1 | class1 | |
+-----+------------+------+
| 2 | class2 | |
+-----+------------+------+
| 3 | class3 |class1|
+-----+------------+------+
| 4 | class4 |class3|
+-----+------------+------+
| 5 | class5 |class2|
+-----+------------+------+
我写的语句如下
select top 1000 id,cname,
case up
when 0 then ' '
else (select cname from k_webclass where id = up)
end as up
from k_webclass where dname= 'lxyes.com ' and lock=0
但是当up不为0是up返回的是null而不是父目录的cname请问如何解决
[解决办法]
(select a.cname from k_webclass a where a.id = k_webclass .up)
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
最新版本:20070212
http://www.cnblogs.com/feiyun0112/archive/2006/09/20/509783.html
[解决办法]
select top 1000 id,cname,
case up
when 0 then ' '
else (select cname from k_webclass where id = t.up)
end as up
from k_webclass as t where dname= 'lxyes.com ' and lock=0