sql语句:UPDATE `vol`.`test_number` SET `ProductCode` = '33', `ProductName` = '1', `NumberQty` = 0 WHERE `id` = 3; 用SqlSugar写这个SQL语句
时间: 2023-04-10 08:01:16 浏览: 100
可以使用以下代码:
var db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "your connection string",
DbType = DbType.MySql,
IsAutoCloseConnection = true
});
db.Updateable<TestNumber>()
.SetColumns(t => new TestNumber()
{
ProductCode = "33",
ProductName = "1",
NumberQty = 0
})
.Where(t => t.Id == 3)
.ExecuteCommand();
相关问题
sql语句:INSERT INTO `vol`.`test_number`(`ProductCode`, `ProductName`, `NumberQty`) VALUES ('tt', 'ss', 199);用SqlSugar写这个SQL语句
Sure, here's how you can write this SQL statement using SqlSugar:
var db = new SqlSugarClient(new ConnectionConfig()
{
ConnectionString = "your_connection_string_here",
DbType = DbType.MySql, // or DbType.SqlServer, DbType.Oracle, etc.
IsAutoCloseConnection = true
});
var testNumber = new TestNumber()
{
ProductCode = "tt",
ProductName = "ss",
NumberQty = 199
};
db.Insertable(testNumber).ExecuteCommand();
Note: You need to replace "your_connection_string_here" with your actual database connection string, and define the TestNumber class with the same properties as the test_number table.
function getPagedList(contractId) { var contractId = body.param.contractId; var sql = ` SELECT a.id, a.contract_id contractId, a.product_id productId, a.purchase_num purchaseNum, a.purchase_price purchasePrice, a.remark, b.product_name productName, b.spec_code specCode, c.type_name typeName, d.unitcode unitCode FROM mes214820519.wms_pur_list_214820519 a, mes214820519.wms_product_214820519 b, mes214820519.wms_product_class_214820519 c, mes214820519.wms_unit_code_214820519 d WHERE a.product_id=b.id AND b.product_class_id = c.id AND b.unit_code_id=d.id AND a.contract_id=#{contractId}`; return db.pager(sql, {contractId: contractId}) } 用JavaScript语言修改这段代码
function getPagedList(contractId) {
var sql = `SELECT
a.id,
a.contract_id as contractId,
a.product_id as productId,
a.purchase_num as purchaseNum,
a.purchase_price as purchasePrice,
a.remark,
b.product_name as productName,
b.spec_code as specCode,
c.type_name as typeName,
d.unitcode as unitCode
FROM
mes214820519.wms_pur_list_214820519 a
INNER JOIN mes214820519.wms_product_214820519 b
ON a.product_id = b.id
INNER JOIN mes214820519.wms_product_class_214820519 c
ON b.product_class_id = c.id
INNER JOIN mes214820519.wms_unit_code_214820519 d
ON b.unit_code_id = d.id
WHERE
a.contract_id = :contractId`;
return db.pager(sql, { contractId: contractId });
}
在修改后的代码中,我使用了ES6模板字符串来构建SQL语句,同时使用了INNER JOIN来连接多张表,使代码更加简洁易读。另外,我还使用了命名参数代替了原来的占位符,以提高代码的可读性和可维护性。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)