| 发表于:2007-04-17 14:31:309楼 得分:0 |
paoluo(一天到晚游泳的鱼)的写法是对的,学习:) 整理一下,借用了paoluo(一天到晚游泳的鱼)的写法: create table t1( dwid int, dwname varchar(10), dwparentid char(1) ) insert t1 select 1, 'aaa ', '0 ' union all select 2, 'bbb ', '1 ' union all select 3, 'ccc ', '1 ' union all select 4, 'ddd ', '2 ' create table t2( gzid int, gzname varchar(10), gzdw char(1) ) insert t2 select 1, 'mmm ', '2 'union all select 2, 'xxx ', '3 'union all select 3, 'yyy ', '3 ' select id, name, parentid from ( select dwid as id, dwname as name, dwparentid as parentid, 0 as flag, dwid as orderid from t1 union all select *, 1 as flag, gzdw from t2 ) a order by orderid, flag, id --result: id name parentid -------------------------- 1 aaa 0 2 bbb 1 1 mmm 2 3 ccc 1 2 xxx 3 3 yyy 3 4 ddd 2 | | |
|