求一sql语句 行转列

xjis00 2004-06-21 05:15:13
COL1 COL2 COL3 COL4
----------------------------
表里面得内容为:
COL1 COL2 COL3 COL4
----------------------------
A B 1 125
A B 2 250
A B 3 330
A B 4 440
A B 5 570
........

现在要显示为
COL1 COL2 COL3 COL4 COL5 COL6 COL7 .....
------------------------------------------------------------
A B 1 125 250 330 440 ....

总之是COL1和COL2 相等的 都显示在一行上面 怎么写这样的sql语句?
...全文
111 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
kirao 2004-06-22
  • 打赏
  • 举报
回复
建議你用pb的交叉報表!
紫炎圣骑 2004-06-22
  • 打赏
  • 举报
回复
用交叉表比较方便的!
jxc 2004-06-22
  • 打赏
  • 举报
回复
写死的语法:

select col1,col2
,max((select sum(b.col4) from test b where b.col1=a.col1 and b.col2=a.col2 and b.col3 = '1')) c1
,max((select sum(b.col4) from test b where b.col1=a.col1 and b.col2=a.col2 and b.col3 = '2')) c2
,max((select sum(b.col4) from test b where b.col1=a.col1 and b.col2=a.col2 and b.col3 = '3')) c3
,max((select sum(b.col4) from test b where b.col1=a.col1 and b.col2=a.col2 and
b.col3 = '4')) c4
,max((select sum(b.col4) from test b where b.col1=a.col1 and b.col2=a.col2 and b.col3 = '5')) c5
from test a
group by col1,col2
/
ghost34 2004-06-21
  • 打赏
  • 举报
回复
sql写个交叉表.
mittee 2004-06-21
  • 打赏
  • 举报
回复
写挺麻烦的,
用交叉表行不?

1,075

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 相关问题讨论
社区管理员
  • 基础类社区
  • WorldMobile
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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