图书:
       书号    单价      书名
        001    12.00     计算机应用
        002    10.00     化学
        003    15.00     分析化学
订书单:
                班级    书号   数量   款项 
               化95.4    001    47    0.00
               数94.3    002    74    0.00
               物96.4    003    67    0.00
               生95.4    002    47    0.00
               地94.3    001    67    0.00
               物94.3    002    67    0.00
               数94.3    001    74    0.00
               化95.4    003    47    0.00
               数94.3    003    74    0.00最后的款项如何怎么写SQL语句?   就是计算订单表的数量乘上图书表的单价?

解决方案 »

  1.   

    select 班级,b.书号,数量,to_char((数量 * 单价),'999,999.99') 款项 
    from 图书 a,订书单 b
    where a.书号 = b.书号;
      

  2.   

    你的款项如果是字符型的可以这样写
    如果是数字型的,就不需要to_char,不过不能完全满足你的需求,比如数值型的12.00  oracle只能保存成12
      

  3.   

    不好意思。
    我说的不是查询;我要的是update更新进款项字段。即把计算订单表的数量乘上图书表的单价结果update到款项的字段。
      

  4.   

    update 订书单 set
    款项 = to_char((数量 * 单价),'999,999.99')
    from 图书 a,订书单 b
    where a.书号 = b.书号;
      

  5.   

    做个小例子
    楼主试试看行不行
    SQL> select * from books;        ID      PRICE NAME
    ---------- ---------- --------------------
             1         10 计算机SQL> select * from orders;CLASS                        ID   QUANTITY      TOTAL
    -------------------- ---------- ---------- ----------
    化95.4                        1         20          0
    SQL> update orders
      2  set total=quantity*(select price from books where books.id=orders.id);1 row updated.SQL> select * from orders;CLASS                        ID   QUANTITY      TOTAL
    -------------------- ---------- ---------- ----------
    化95.4                        1         20        200
      

  6.   

    SQL> update orders set
      2  total=quantity*price
      3  from books a,orders b
      4  where a.id=b.id;
    from books a,orders b
    *
    ERROR at line 3:
    ORA-00933: SQL command not properly ended
    ORACLE里好像不能这样写
      

  7.   


    大哥那样是查询不是批量更新。要是在JDBC里就好做多了。
      

  8.   

    UPDATE   order_info_table aa
       SET   totalprice =
                (SELECT   sumprice
                   FROM   (SELECT   a.bookid,b.class, price * amount sumprice
                             FROM   bookinfo_table a, order_info_table b
                            WHERE   a.bookid = b.bookid) c
                  WHERE   c.class = aa.class and c.bookid=aa.bookid)
     WHERE   aa.class IN (SELECT   class FROM order_info_table);测试已通过。
      

  9.   

    update 订书单 d
    set 款项 = 
    (
    select 款项 from  
    (
    select 班级,b.书号,数量,to_char((数量 * 单价),'999,999.99') 款项 
    from 图书 a,订书单 b 
    where a.书号 = b.书号
    )c
    where d.班级 = c.班级 and d.书号=c.书号
    );