寻求数据的行列互换方法!急!!!

wildwolf_syq 2003-12-12 07:06:17
各位高手,你在开发中有没有碰到这样的问题,你的数据在数据库中室分多行存储的,用户要求多行数据在统一行上显示,应该如何解决??有什么好的方法吗?多谢!!如有可以把代码写上吗??
...全文
28 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lmby 2003-12-12
  • 打赏
  • 举报
回复
用CROSS TAB比较好

或者用SQL,效率不高,但可能灵活点

select temp.工号,
(select 金额 from 工资表 where 工资表.工号 = temp.工号 and 工资表.工资项目 = '基本工资') as 基本工资,
(select 金额 from 工资表 where 工资表.工号 = temp.工号 and 工资表.工资项目 = '岗位工资') as 岗位工资,
(select 金额 from 工资表 where 工资表.工号 = temp.工号 and 工资表.工资项目 = '加班工资') as 加班工资,
(select 金额 from 工资表 where 工资表.工号 = temp.工号 and 工资表.工资项目 = '夜班费') as 夜班费,
(select 金额 from 工资表 where 工资表.工号 = temp.工号 and 工资表.工资项目 = '养老金') as 养老金,
(select 金额 from 工资表 where 工资表.工号 = temp.工号 and 工资表.工资项目 = '公积金') as 公积金
from
(select distinct 工号 from 工资表) as temp
eminena 2003-12-12
  • 打赏
  • 举报
回复
用交差表。

754

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder 数据库相关
社区管理员
  • 数据库相关社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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