sql update topic set relation_person_number = relation_person_number-1, real_relation_person_number =real_relation_person_number-1 WHERE id = #{id} 如果relation_person_number-1小于0 就取0怎么写
时间: 2024-02-28 19:54:58 浏览: 76
你可以使用 SQL 中的 CASE 语句来实现这个需求。下面是一个示例代码:
```
UPDATE topic
SET relation_person_number = CASE WHEN relation_person_number-1 < 0 THEN 0 ELSE relation_person_number-1 END,
real_relation_person_number = CASE WHEN real_relation_person_number-1 < 0 THEN 0 ELSE real_relation_person_number-1 END
WHERE id = #{id};
```
这个代码中,使用了 CASE 语句来判断 relation_person_number-1 和 real_relation_person_number-1 是否小于 0,如果小于 0 则将对应的值设置为 0,否则将对应的值减 1。注意,这里使用了 SET 子句来同时更新两个列的值。
相关问题
def _calc(self, h, t, r): # Calculate rotated complex embeddings re_head, im_head = torch.chunk(h, 2, dim=-1) # 头实体:分块 实数域与复数域 re_tail, im_tail = torch.chunk(t, 2, dim=-1) # 尾实体: re_relation, im_relation = torch.chunk(r, 2, dim=-1) # 关系: re_head = torch.unsqueeze(re_head, dim=-1) im_head = torch.unsqueeze(im_head, dim=-1) re_tail = torch.unsqueeze(re_tail, dim=-1) im_tail = torch.unsqueeze(im_tail, dim=-1) # Perform rotation re_h = re_head * re_relation - im_head * im_relation im_h = re_head * im_relation + im_head * re_relation re_t = re_tail * re_relation + im_tail * im_relation im_t = -re_tail * im_relation + im_tail * re_relation # Concatenate real and imaginary part of embeddings h = torch.cat([re_h, im_h], dim=-1) t = torch.cat([re_t, im_t], dim=-1) return h, t解释
这段代码是一个用于在知识图谱中进行实体关系预测的模型中的一个函数。该函数的作用是将头实体、尾实体和关系的复杂向量表示进行旋转,得到新的向量表示。具体来说,该函数首先将头实体、尾实体和关系的复杂向量表示分为实部和虚部两个部分,然后通过旋转公式计算得到新的实部和虚部,最后将实部和虚部拼接起来得到新的向量表示。其中,旋转公式是re_h = re_head * re_relation - im_head * im_relation和im_h = re_head * im_relation + im_head * re_relation,re_t = re_tail * re_relation + im_tail * im_relation和im_t = -re_tail * im_relation + im_tail * re_relation。
UPDATE tb_cust_relation_tags SET cust_id=#{one.}, cust_name=, cust_flag=, cert_no=, credit_no=, tag_id=, tag_name=, tag_view=, tag_value=, data_date= WHERE rel_id = #{one.};补全语句
根据你提供的信息,更新语句应该如下所示:
```
UPDATE tb_cust_relation_tags SET
cust_id=#{one.custId},
cust_name=#{one.custName},
cust_flag=#{one.custFlag},
cert_no=#{one.certNo},
credit_no=#{one.creditNo},
tag_id=#{one.tagId},
tag_name=#{one.tagName},
tag_view=#{one.tagView},
tag_value=#{one.tagValue},
data_date=#{one.dataDate}
WHERE rel_id=#{one.relId};
```
在上述语句中,使用 `SET` 子句指定需要更新的字段及其对应的值,使用 `WHERE` 子句指定更新的条件,这里使用 `rel_id` 字段作为更新条件,值为 `one.relId` 的属性值。另外,需要注意变量名和语句中的字段名是否一致。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.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)