mysql - 数据库更新查询

标签 mysql

这是我之前用来获取总和的查询

    select  E.Id as StaffId,
            SUM(IC.AmountReceived) as totalAmount,INV.InvoiceType as AccountType
            from invoice_collection IC,employee E ,invoice INV
            where IC.CollectedBy=E.id and IC.OperatorCode=#operatorCode#
            and INV.InvoiceNo=IC.InvoiceNo and E.Id=#staffId# and IC.journalFetchStatus=1
            and TxnDate > #CreatedOn#
            group by INV.InvoiceType;

我正在尝试解决具有相同条件的另一个更新问题

update invoice_collection set journalFetchStatus=0
        where IC.CollectedBy=E.id and IC.OperatorCode=#operatorCode#
        and INV.InvoiceNo=IC.InvoiceNo and E.Id=#staffId#
        and TxnDate > #CreatedOn#
        group by INV.InvoiceType;

最佳答案

试试这个:

update invoice_collection IC
 inner join Employee E on IC.CollectedBy=E.id
 inner join invoice INV on INV.InvoiceNo=IC.InvoiceNo
 set journalFetchStatus=0
 where IC.OperatorCode=#operatorCode#
and E.Id=#staffId#
and TxnDate > #CreatedOn#;

关于mysql - 数据库更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35033359/

相关文章:

Mysql SUM 如果不为空则唯一

Mysql全文索引对完全匹配和部分匹配给出相同的分数,为什么?

mysql - rails : Proper way for MySQL query to search multiple attributes

mysql - 按组获取前 10 名值(value)

jquery - mysql中单个表中不同列长度的数据

mysql - group by 和 order by 使 mysql 中的查询非常慢?

mysql - 在线游戏登录设计

mysql - Laravel 条件选择 ->get

php - 使用 CodeIgniter 从 .sql 文件执行 SQL

PHP MySQL 通过 PDO : mysql_result() substitute not working when called more than once