Oracle数据库,如何通过SELECT查询固定行数的数据?
我想建一个视图,内部是一些类似如下的数据col1col2col3123132211但是我现在想要的结果是这样的col1col2col312313211211222sele...
我想建一个视图,内部是一些类似如下的数据
col1 col2 col3
1 2 3
1 3 2
2 1 1
但是我现在想要的结果是这样的
col1 col2 col3
1 2 3
1 3 2
1
1
2 1 1
2
2
2
select出固定行数的数据,如果没有用空来补充,求大家帮帮忙啊! 展开
col1 col2 col3
1 2 3
1 3 2
2 1 1
但是我现在想要的结果是这样的
col1 col2 col3
1 2 3
1 3 2
1
1
2 1 1
2
2
2
select出固定行数的数据,如果没有用空来补充,求大家帮帮忙啊! 展开
展开全部
ROWNUM过滤
eg.select*from tab where rownum=n;
eg.select*from tab where rownum=n;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
with x as
(select '1' col1, '2' col2, '3' col3
from dual
union
select '1' col1, '3' col2, '2' col3
from dual
union
select '2' col1, '1' col2, '1' col3
from dual)
select *
from (select *
from x
union all
select i.col1, null, null
from (select col1, 4 - count(1) cn from x group by col1) i
connect by level <= i.cn
group by i.col1, level)
order by col1, col2, col3
(select '1' col1, '2' col2, '3' col3
from dual
union
select '1' col1, '3' col2, '2' col3
from dual
union
select '2' col1, '1' col2, '1' col3
from dual)
select *
from (select *
from x
union all
select i.col1, null, null
from (select col1, 4 - count(1) cn from x group by col1) i
connect by level <= i.cn
group by i.col1, level)
order by col1, col2, col3
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
with x as
(select '1' col1, '2' col2, '3' col3
from dual
union
select '1' col1, '3' col2, '2' col3
from dual
union
select '2' col1, '1' col2, '1' col3
from dual)
select *
from (select *
from x
union all
select i.col1, null, null
from (select col1, 4 - count(1) cn from x group by col1) i
connect by level <= i.cn
group by i.col1, level)
order by col1, col2, col3
(select '1' col1, '2' col2, '3' col3
from dual
union
select '1' col1, '3' col2, '2' col3
from dual
union
select '2' col1, '1' col2, '1' col3
from dual)
select *
from (select *
from x
union all
select i.col1, null, null
from (select col1, 4 - count(1) cn from x group by col1) i
connect by level <= i.cn
group by i.col1, level)
order by col1, col2, col3
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
看不懂,你的固定行有什么判断条件没有?或者什么?
追问
比如说现在col1列为1的是2条数据,col1为2的是1条数据,我想要col1为1的4条数据,另外两条空着;col1为2的4条数据,其他3条空着。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询