(非公司系统表)
#
1 | select t1.id t1_id,t2.id t2_id,t1.file_id t1_file_id,t2.file_id t2_file_id,t2.file_name file_name from (select * from attachments where file_id=0) t1 left join (select * from attachments where id in ( select max(id) max_id from attachments where file_id!=0 and contract_id in (select contract_id from attachments where file_id=0) group by contract_id )) t2 on t1.contract_id =t2.contract_id ; |
1 | select concat('update attachments set file_id=',t2_file_id,'where id=',t1_id,';') from (select t1.id t1_id,t2.id t2_id,t1.file_id t1_file_id,t2.file_id t2_file_id,t2.file_name file_name from (select * from attachments where file_id=0) t1 left join (select * from attachments where id in ( select max(id) max_id from attachments where file_id!=0 and contract_id in (select contract_id from attachments where file_id=0) group by personnel_contract_id )) t2 on t1.contract_id =t2.contract_id ) as t3; |
exist 使用
1 | -- 查询不存在某表的数据exists |
行转列
1 |
|
1 |
|