如果不加customer_name这个条件就很快,加了这个条件就慢了
时间: 2023-02-07 11:42:08 浏览: 63
如果你的查询中包含了一个自定义的名字条件(例如 "customer_name"),那么查询的速度可能会变慢。这是因为在执行查询时,数据库需要在表中搜索匹配该名称的所有行,这会导致查询的执行时间变长。如果不加这个条件,那么查询就会更快,因为数据库不需要在表中搜索任何特定的名称。
相关问题
select customer_name from customer where customer_street like '%Main%'
这是一个 SQL 查询语句,意思是从名为 `customer` 的表中选择 `customer_name` 列,其中 `customer_street` 包含字符串 "Main" 的所有行。
`LIKE` 操作符用于模糊匹配,`%` 表示匹配任意数量(包括零个)的任意字符。因此,`'%Main%'` 表示匹配包含 "Main" 子字符串的任何值。
这个查询语句将返回符合条件的所有行的 `customer_name` 列的值。
let column_head_order_no, column_old_order_code, column_customer_name, column_head_memo,column_order_date, column_sum_tax_amount,column_creator,column_customer_tax_id,column_customer_address, column_customer_tel,column_customer_bank,column_customer_bank_account,column_customer_email,column_org_name advanceConfig.value.apiKingdeeDetailTableSetting.mainTableField.forEach(item => { if (item.name === 'order_no') { column_head_order_no = item.field_name } if (item.name === 'old_order_code') { column_old_order_code = item.field_name } if (item.name === 'customer_name') { column_customer_name = item.field_name } if (item.name === 'memo') { column_head_memo = item.field_name } if (item.name === 'order_date') { column_order_date = item.field_name } if (item.name === 'sum_tax_amount') { column_sum_tax_amount = item.field_name } if (item.name === 'sum_tax_amount') { column_sum_tax_amount = item.field_name } }) 优化这段代码
可以使用对象字面量和数组的解构来简化这段代码:
```
const fieldMap = {
order_no: 'column_head_order_no',
old_order_code: 'column_old_order_code',
customer_name: 'column_customer_name',
memo: 'column_head_memo',
order_date: 'column_order_date',
sum_tax_amount: 'column_sum_tax_amount',
creator: 'column_creator',
customer_tax_id: 'column_customer_tax_id',
customer_address: 'column_customer_address',
customer_tel: 'column_customer_tel',
customer_bank: 'column_customer_bank',
customer_bank_account: 'column_customer_bank_account',
customer_email: 'column_customer_email',
org_name: 'column_org_name'
}
const columns = {}
advanceConfig.value.apiKingdeeDetailTableSetting.mainTableField.forEach(item => {
if (fieldMap[item.name]) {
columns[fieldMap[item.name]] = item.field_name
}
})
```
这样可以去除大量的重复代码,同时也更加易读和易于维护。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)