b12345678b 2013-09-14 07:41 采纳率: 0%
浏览 3092

两张无关联表 根据时间这么累计金额?求SQL语句或解决方案

表A id datetime pay(收入表)
表B id Bdatetime pay(支出表)

A:
1 2012-08-19 22.00
2 2012-09-23 32.00
3 2012-09-30 33.00
B:
1 2012-08-20 -11.00
2 2012-09-24 -20.00
输出:
C:(id Cdatetime pay paycount)
1 2012-08-19 22.00 22.00
2 2012-08-20 -11.00 11.00
3 2012-09-23 32.00 43.00
4 2012-09-24 -20.00 23.00

  • 写回答

3条回答 默认 最新

  • 马欢欢 2013-09-14 09:08
    关注

    一个sql语句应该无法完成。
    建议使用TABLE函数实现。TABLE函数使用不负责。
    例:

    create or replace type t_test as object(
    id integer,
    rq date,
    mc varchar2(60)
    )
    /
    create or replace type t_test_table as table of t_test
    /
    
    create or replace function f_test_pipe(n in number default null) return t_test_table PIPELINED 
    as 
    v_test t_test_table := t_test_table();
    begin 
    for i in 1 .. nvl(n,100) loop
    pipe row(t_test(i,sysdate,'mc'||i)); 
    end loop; 
    return; 
    end f_test_pipe; 
    /
    select * from table(f_test_pipe(20))
    /
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥20 为什么我写出来的绘图程序是这样的,有没有lao哥改一下
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥200 关于#c++#的问题,请各位专家解答!网站的邀请码
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号