急求Sql语句呀,在线等。

xkcm 2006-09-21 10:28:18
表T1资源总表
a1 a2 b1 b2
50 60 70 80
30 20 10 5

想得到如下视图

1 a1 50
2 a1 30
3 a2 60
4 a2 20
5 b1 70
6 b1 10
7 b2 80
8 b2 5

这种Sql怎么写?急呀,在线等。
...全文
210 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
xkcm 2006-09-22
  • 打赏
  • 举报
回复
楼上的朋友,不行呀,执行不通过呀。
sten 2006-09-22
  • 打赏
  • 举报
回复
select rownum rid,tab_a.* from
(
select 'a1' colname,to_char(a1) value
from t1
union all
select 'a2' colname,to_char(a2) value
from t1
union all
select 'b1' colname,to_char(b1) value
from t1
union all
select 'b2' colname,to_char(b2) value
from t1
) tab_a
这样试试,不会有问题的
Eric_1999 2006-09-22
  • 打赏
  • 举报
回复
不是很懂楼主意思。
a1 a2 b1 b2
50 60 70 80
30 20 10 5
行列都固定吗?
snowy_howe 2006-09-22
  • 打赏
  • 举报
回复
楼上的朋友,不行呀,执行不通过呀。


难道连错误信息也没有吗????????????
!!!!!!!!!!!!!!!!!!!!!!!!!
Eric_1999 2006-09-22
  • 打赏
  • 举报
回复
select rownum, x.*
from (
select * from tab t where t.a1 = a1
union all
select * from tab t where t.a2 = a2
union all
select * from tab t where t.b1 = b1
union all
select * from tab t where t.b2 = b2
) x
Eric_1999 2006-09-22
  • 打赏
  • 举报
回复
select rownum, x.*
from (
select * from tab t where t.a1 = a1
union all
select * from tab t where t.a2 = a2
union all
select * from tab t where t.b1 = b1
union all
select * from tab t where t.b2 = b2
)
wiler 2006-09-22
  • 打赏
  • 举报
回复
是不是各个列的类型不一样啊?这样改看看
select rownum rid,tab_a.* from
(
select 'a1' colname,to_number(a1) value
from t1
union all
select 'a2' colname,to_number(a2) value
from t1
union all
select 'b1' colname,to_number(b1) value
from t1
union all
select 'b2' colname,to_number(b2) value
from t1
) tab_a
allright_flash 2006-09-22
  • 打赏
  • 举报
回复
select rownum, x.*
from (
select 'a1' colname from tab t where t.a1 = a1
union all
select 'a2' colname from tab t where t.a2 = a2
union all
select 'b1' colname from tab t where t.b1 = b1
union all
select 'b2' colname from tab t where t.b2 = b2
) x
wiler 2006-09-21
  • 打赏
  • 举报
回复
select rownum rid,tab_a.* from
(
select 'a1' colname,a1 value
from t1
union all
select 'a2' colname,a2 value
from t1
union all
select 'b1' colname,b1 value
from t1
union all
select 'b2' colname,b2 value
from t1
) tab_a

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧