update b.sheet_id=t.sheet_id set bpm_ins_proc_t t left join bp_consum_material_in_main b on t.ins_proc_id = b.id where t.proc_id=502 and b.is_deleted=0
时间: 2024-04-07 20:29:17 浏览: 20
这是一个 SQL 语句,与你之前提供的语句相比,只是将更新语句中的表名和字段名进行了交换。更准确地说,它将表 bpm_ins_proc_t 的 sheet_id 字段更新为表 bp_consum_material_in_main 的 sheet_id 字段的值,条件是 bpm_ins_proc_t 的 proc_id 字段等于 502,同时 bp_consum_material_in_main 的 is_deleted 字段为 0。使用左连接(left join)将两个表关联起来,关联条件是 bpm_ins_proc_t 的 ins_proc_id 字段等于 bp_consum_material_in_main 的 id 字段。
相关问题
update t.sheet_id=b.sheet_id set bpm_ins_proc_t t left join bp_consum_material_in_main b on t.ins_proc_id = b.id where t.proc_id=502 and b.is_deleted=0
这是一个 SQL 语句,用于更新表 bpm_ins_proc_t 的 sheet_id 字段,将其值设为表 bp_consum_material_in_main 的 sheet_id 字段的值,条件是 bpm_ins_proc_t 的 proc_id 字段等于 502,同时 bp_consum_material_in_main 的 is_deleted 字段为 0。使用左连接(left join)将两个表关联起来,关联条件是 bpm_ins_proc_t 的 ins_proc_id 字段等于 bp_consum_material_in_main 的 id 字段。
<select id="findHdRectorder" parameterType="com.tst.model.hd.HdRectorder" resultType="com.tst.model.hd.HdRectorder"> select h.*, (select process_bar from hd_rectorder_task t where t.hd_no=h.hd_no and t.sta_time=(select max(sta_time) from hd_rectorder_task t1 where t1.hd_no=h.hd_no and t1.status=2) limit 1), (select major_name from sec_major m where h.major_id=m.major_id) major, u.name create_name, u.phone create_phone, u2.name rect_name, u2.phone rect_phone, u3.name concert_name, u3.phone concert_phone, p.proc_name, (select name from te_geoloc t where h.cityid=t.mnodeid and h.cityid>0) cityname, (select name from te_geoloc t where h.areaid=t.id) areaname from hd_rectorder h left join sec_user u on h.create_by=u.username left join sec_user u2 on h.rect_user=u2.username left join sec_user u3 on h.concert_user=u3.username left join hd_rectorder_proc p on h.hd_proc_id = p.proc_id where 1=1 <if test="hd_proc_id!=null and hd_proc_id>0"> and h.hd_proc_id=#{hd_proc_id} </if> </select> 有这样一条sql 其中hd_proc_id有0,1,2,3,4,5,6 其中0表示未处置 1,2,3,4,5都是表示已经处置 但是在不同的状态 如何获取在处置的数据 怎么改进
根据这条SQL语句,可以看出`hd_proc_id`字段表示处置的状态,其中0表示未处置,而1、2、3、4、5表示已经处置但是在不同的状态。如果你想获取已处置的数据,可以将条件修改为`hd_proc_id>0`,这样就可以排除未处置的数据,只获取已处置的数据。
改进的话,可以考虑将条件逻辑进行优化,使用更直观的方式表示已处置的状态。比如,可以使用一个字段来表示处置状态,而不是使用多个数字来表示不同的状态。这样可以简化SQL语句,并且更易于理解和维护。
另外,可以考虑使用索引来优化查询性能,特别是在处理大量数据时。根据具体情况,可以为关键字段添加索引,以加快查询速度。
总结起来,你可以按照以上建议进行改进:
1. 修改条件为`hd_proc_id>0`以获取已处置的数据。
2. 考虑使用一个字段来表示处置状态,简化SQL语句。
3. 根据具体情况使用索引来优化查询性能。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)