UPDATE BG_BY_DAY_DTL1 byd SET CACULATE_UNIT_PCS =(SELECT CACULATE_UNIT_PCS FROM BG_DB_PRO_COM_TYPE pct where byd.PRODUCT_CODE=pct.PRODUCT_CODE) where byd.CACULATE_UNIT_PCS is null
时间: 2023-08-05 07:08:08 浏览: 98
你好!根据你的要求,我可以给你一个SQL语句的建议来更新表格BG_BY_DAY_DTL1中的数据。请注意,我只提供了一个示例,具体的语法可能需要根据你的数据库类型和表结构进行调整。
以下是我提供的SQL语句:
```sql
UPDATE BG_BY_DAY_DTL1 byd
SET byd.CACULATE_UNIT_PCS = (
SELECT pct.CACULATE_UNIT_PCS
FROM BG_DB_PRO_COM_TYPE pct
WHERE byd.PRODUCT_CODE = pct.PRODUCT_CODE
)
WHERE byd.CACULATE_UNIT_PCS IS NULL;
```
这个SQL语句会将BG_BY_DAY_DTL1表中CACULATE_UNIT_PCS为空的记录更新为BG_DB_PRO_COM_TYPE表中对应PRODUCT_CODE的CACULATE_UNIT_PCS值。
请确保在执行任何数据库操作之前备份数据,并仔细验证和测试语句的正确性和适用性。
相关问题
update gd_zbiti.rpt_dtl_7650_ssc_schcb w join (select distinct l.writeoff_instance_id,l.supplier_code,l.supplier_name from ctgmss.bz_mss_writeoff_inst_to_supplier l ) z2 on z2.writeoff_instance_id=w.instance_id set w.supplier_code = z2.supplier_code ,w.supplier_name = z2.supplier_name;
你的更新语句看起来是正确的,它将从子查询中获取的供应商代码和供应商名称更新到表 gd_zbiti.rpt_dtl_7650_ssc_schcb 的相应行中。这将根据 writeoff_instance_id 和 instance_id 列之间的匹配进行操作。请确保所使用的列名和表名是正确的,并且数据库连接是有效的。如果有任何错误或问题,请提供更多详细信息以便我能够帮助你更好。
UPDATE a SET a.refund_status = b.dealstat , a.refund_time = b.dealtime FROM dwi_store_setmt_ord_dtl_p a INNER JOIN sdi_dgmps_dgmpsdb_mstore.chainstorefeemangdtl_p b ON a.comp_code = trim(upper(b.companycode)) AND a.src_pid = trim(b.pid) WHERE a.refund_status = 0 AND ISNULL(a.refund_time,'') = '' AND b.dealstat = 1 AND ISNULL(a.dealtime,'') <> '' ;改为用merge into 更新
Sure, here's the equivalent MERGE statement:
```
MERGE INTO dwi_store_setmt_ord_dtl_p AS a
USING (
SELECT trim(upper(b.companycode)) AS comp_code,
trim(b.pid) AS src_pid,
b.dealstat,
b.dealtime
FROM sdi_dgmps_dgmpsdb_mstore.chainstorefeemangdtl_p AS b
WHERE b.dealstat = 1
) AS b
ON a.comp_code = b.comp_code
AND a.src_pid = b.src_pid
AND a.refund_status = 0
AND ISNULL(a.refund_time, '') = ''
AND ISNULL(a.dealtime, '') <> ''
WHEN MATCHED THEN
UPDATE SET a.refund_status = b.dealstat,
a.refund_time = b.dealtime;
```
This MERGE statement combines the source table `sdi_dgmps_dgmpsdb_mstore.chainstorefeemangdtl_p` with the target table `dwi_store_setmt_ord_dtl_p` based on the matching conditions specified in the ON clause. When a match is found, the specified columns in the target table are updated with the corresponding values from the source table.
阅读全文