Update statement using with clause

前端 未结 3 1807
醉梦人生
醉梦人生 2020-12-24 01:04

I have a script that uses a stack of with clauses to come up with some result, and then I want to write that result in a table. I just can\'t get my head around it, could so

3条回答
  •  甜味超标
    2020-12-24 01:46

    If anyone comes here after me, this is the answer that worked for me.

    NOTE: please make to read the comments before using this, this not complete. The best advice for update queries I can give is to switch to SqlServer ;)

    update mytable t
    set z = (
      with comp as (
        select b.*, 42 as computed 
        from mytable t 
        where bs_id = 1
      )
      select c.computed
      from  comp c
      where c.id = t.id
    )
    

    Good luck,

    GJ

提交回复
热议问题