表结构
PriceTypeid   varchar(25)
Ptypeid       varchar(25)
Price         numeric(13)
表如下
pricetypeid ptypeid    price
LSSJ1       0001       0
YSSJ1       0001       10
现在要把YSSJ1 对应的PRICE 复制到LSSJ1
这个语句应该怎么写呢。
谢谢各位朋友

解决方案 »

  1.   

    现在要把YSSJ1 对应的PRICE 复制到LSSJ1 ?结果是这样?pricetypeid ptypeid    price 
    LSSJ10       0001       0 
    YSSJ110       0001       10 
      

  2.   

    要这个结果pricetypeid ptypeid    price 
    LSSJ1       0001       10
    YSSJ1       0001       10 
    ptypeid下面还有其它商品
    pricetypeid ptypeid    price 
    LSSJ1       0001       0 
    YSSJ1       0001       10 
    LSSJ1       0002       20
    YSSJ1       0002       10 
      

  3.   


    update 表 set price=B.price
     from 表 A,
          (select * from A where pricetypeid='YSSJ1') B
    where A.pricetypeid='LSSJ1'
      and A.ptypeid =B.ptypeid 
      

  4.   

    只更新0001的数据的话update 表 set price=B.price
     from 表 A,
          (select * from A where pricetypeid='YSSJ1') B
    where A.pricetypeid='LSSJ1'
      and A.ptypeid =B.ptypeid 
      and A.ptypeid ='0001'
      

  5.   

    pricetypeid ptypeid    price 
    LSSJ1       0001       0 
    YSSJ1       0001       10 
    现在要把YSSJ1 对应的PRICE 复制到LSSJ1 
    这个语句应该怎么写呢。 
    ------------------------
    update t
    set price=b.price
    from t a left join(select * from t where pricetypeid ='YSSJ1') b
    on a.ptypeid=b.ptypeid    
    where a.pricetypeid='LSSJ1'