Home > database >  Three table changes to the SQL how to write
Three table changes to the SQL how to write

Time:09-24

Want to write a SQL, according to the user's department, now update requirements in the table duty_deptid, duty_deptname, duty_deptnameall these three field values,
Fields in the table including xq demand duty_userid duty_username, duty_deptid, duty_deptname, duty_deptnameall, user fields in the table userid, username, fk_deptid, dept department fields in the table deptid, the deptname, deptnamall, user table fk_deptid is foreign keys, related departments in the table deptid, general situation is such, so questions can clear? To change this sentence how to write,

CodePudding user response:

 
The update
(the select xq. Duty_deptid didxq, duty_deptname dnamexq, duty_deptnameall dnameallxq,
D.d eptid didd, d.d eptname dnamed, d.d eptnameall dnamealld
The from xq, user dept d
Where xq. Duty_userid=user. Userid
And the user. Fk_deptid=d.d eptid)
Set didxq=didd, dnamexq=dnamed, dnameallxq=dnamealld

CodePudding user response:

The update xq set xq duty_deptid, xq. Duty_deptname, xq. Duty_deptnameall
(the select dept. Deptid, deptdeptname, dept. Deptnamall from dept, user where dept. The deptid=user. Fk_deptid
And xq. Duty_userid=user. Userid);
  • Related