0

我正在尝试从不同的表中更新两个:

$query = "UPDATE ".$SupportTicketsTable." a ,".$SupportUserTable." b 
SET a.ticket_status=0, 
    b.solved_tickets= CASE WHEN a.ticket_status!='0' THEN (b.solved_tickets+1) ELSE b.solved_tickets END , 
    b.assigned_tickets= CASE  WHEN a.ticket_status!='0' AND b.assigned_tickets>=1 THEN (b.assigned_tickets-1) ELSE b.assigned_tickets END ,
    a.ticket_status='0' 
    WHERE a.enc_id=? AND b.id=a.operator_id";

但这仅在 b.id 存在时才有效,否则它不会做任何事情,但我的目标是更新 tick a.ticket_ststus
我尝试使用OR而不是,AND但它返回重复键错误或更新错误b.assigned_ticket
提前感谢

编辑

感谢您提供的信息,我尝试过这样的事情:

$query = "UPDATE a
        SET 
            b.solved_tickets= CASE WHEN a.ticket_status!='0' THEN (b.solved_tickets+1) ELSE b.solved_tickets END , 
            b.assigned_tickets= CASE  WHEN a.ticket_status!='0' AND b.assigned_tickets>=1 THEN (b.assigned_tickets-1) ELSE b.assigned_tickets END ,
            a.ticket_status=0
        FROM ".$SupportTicketsTable." a
        LEFT OUTER JOIN ".$SupportUserTable." b
        ON b.id=a.operator_id
        WHERE a.enc_id=? ";

但它说之前有一个错误FROM ".$SupportTicketsTable." a,但我不明白它错了什么

4

1 回答 1

0

已解决(感谢帮助):

 $query = "UPDATE ".$SupportTicketsTable." a
                LEFT OUTER JOIN ".$SupportUserTable." b
                ON b.id=a.operator_id
                SET 
                    b.solved_tickets= CASE WHEN a.ticket_status!='0' THEN (b.solved_tickets+1) ELSE b.solved_tickets END , 
                    b.assigned_tickets= CASE  WHEN a.ticket_status!='0' AND b.assigned_tickets>=1 THEN (b.assigned_tickets-1) ELSE b.assigned_tickets END ,
                    a.ticket_status='0'
                WHERE a.enc_id=? ";
于 2013-07-28T09:49:07.133 回答