MySQL - UPDATE query based on SELECT Query

后端 未结 11 2212
既然无缘
既然无缘 2020-11-21 23:58

I need to check (from the same table) if there is an association between two events based on date-time.

One set of data will contain the ending date-time of certain

11条回答
  •  春和景丽
    2020-11-22 00:54

    UPDATE 
      receipt_invoices dest,
      (
        SELECT 
          `receipt_id`,
          CAST((net * 100) / 112 AS DECIMAL (11, 2)) witoutvat 
        FROM
          receipt 
        WHERE CAST((net * 100) / 112 AS DECIMAL (11, 2)) != total 
          AND vat_percentage = 12
      ) src 
    SET
      dest.price = src.witoutvat,
      dest.amount = src.witoutvat 
    WHERE col_tobefixed = 1 
      AND dest.`receipt_id` = src.receipt_id ;
    

    Hope this will help you in a case where you have to match and update between two tables.

提交回复
热议问题