用一条SQL实现这样的效果
有表A,字段ID,NAME
ID,NAME
1,'A'
2,'B'
3,'C'
5,'D'
6,'E'
现要求达到以下效果
ID,NAME
1,'A'
2,'B'
3,'C'
4,''
5,'D'
6,'E'
方法一如下:
SELECT b.lv ID, a.NAME NAME
FROM a, (SELECT LEVEL lv FROM dual CONNECT BY LEVEL <= 6) b
WHERE b.lv = a.id(+)
ORDER BY 1;
方法二(比较笨,不推荐):
select id,name from test001
union
select id,'' from (select rownum as id from dual connect by rownum <=(selec
t max(id) from test001))
4 where id not in(select id from test001);
阅读(1313) | 评论(0) | 转发(0) |