简化mysql select CASE WHEN #{company_type} not in ('Downstream', 'Shipment', 'Supplier') then (SELECT count(1) FROM scf_custom_company WHERE id <> #{id} AND tenant_id = #{_tenantId} AND bcm_deleted = 'N' AND company_type = #{company_type} AND company_credit_code = #{companyCreditCode} ) ELSE ( SELECT count(1) FROM scf_custom_company WHERE id <> #{id} AND tenant_id = #{_tenantId} AND bcm_deleted = 'N' AND company_type = #{company_type} AND (parent_org_code <> #{parentOrgCode} or parent_org_code is null) AND company_credit_code = #{companyCreditCode} ) end
时间: 2023-11-27 10:49:26 浏览: 165
这是一条 MySQL 查询语句,根据不同的条件选择不同的查询方式,可以简化为以下代码:
```
SELECT count(1) FROM scf_custom_company
WHERE id <> #{id} AND tenant_id = #{_tenantId} AND bcm_deleted = 'N'
AND company_type = #{company_type} AND company_credit_code = #{companyCreditCode}
AND (
(#{company_type} NOT IN ('Downstream', 'Shipment', 'Supplier') AND parent_org_code = #{parentOrgCode})
OR
(#{company_type} IN ('Downstream', 'Shipment', 'Supplier') AND (parent_org_code <> #{parentOrgCode} OR parent_org_code IS NULL))
)
```
其中,`#{}` 表示占位符,需要在实际执行查询时替换成具体的值。这条语句的作用是统计符合条件的记录数。
相关问题
how to use utils.save_checkpoint for downstream task
To use utils.save_checkpoint for a downstream task, you need to first define the model and optimizer for your task, and then checkpoint your current model and optimizer using the provided function. Here is an example:
First, define your model and optimizer:
model = MyDownstreamModel()
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
Then, train your model and periodically save checkpoints:
for epoch in range(num_epochs):
# train your model
# ...
# save checkpoint
utils.save_checkpoint({
'epoch': epoch + 1,
'state_dict': model.state_dict(),
'optimizer': optimizer.state_dict(),
})
This will save your model's state_dict and your optimizer's state_dict to a file named 'checkpoint.pth.tar' in the current directory. You can load this checkpoint later by using the provided utils.load_checkpoint function.
self.avg_pool = nn.AdaptiveAvgPool2d((1, 1))
This code snippet creates an instance of the nn.AdaptiveAvgPool2d module with a target output size of (1, 1).
The AdaptiveAvgPool2d module is used for global average pooling, which is a technique commonly used in convolutional neural networks for image classification. It takes as input a tensor of shape (batch_size, channels, height, width), and computes the average value of each channel across all spatial dimensions (height and width) to produce a tensor of shape (batch_size, channels, 1, 1).
By setting the output size to (1, 1), the module ensures that the resulting tensor has a fixed size regardless of the input size, which can be useful for downstream layers that require a fixed input size.
阅读全文