Making select and update in one query

后端 未结 1 385
星月不相逢
星月不相逢 2021-01-15 00:21

is there a query where I can do both querys in one?

This is the first

$q = \"select c.id as campaignId,c.priceFactor,
              o.cid,o.bloggerPr         


        
相关标签:
1条回答
  • 2021-01-15 00:58

    In MySQL, you can use a join right after UPDATE. In your example, this might look something like:

    update Orders o
    inner join Campaign c on c.id = o.cid
    set
        listPrice = o.priceFactor * order.basicPrice
    ,   bloggerPrice = case 
            when o.bloggerPrice < o.priceFactor * order.basicPrice
                then o.priceFactor * order.basicPrice
                else bloggerPrice
            end
    ,   listPrice = case 
            when o.customerPrice < o.priceFactor * order.basicPrice
                then o.priceFactor * order.basicPrice
                else listPrice
            end
    where o.state in (8,9)
    and c.id = {$campaignId}
    
    0 讨论(0)
提交回复
热议问题