sql 請教update語句in多個值時,進行多次更新
你這個代碼我看的暈暈忽忽的
如果是我
update A SET * = (select amount from B where id = *)
where * in(select id from c where id in(select id from B))
我猜的 你想更新A表 amount 值等于B表 相對應的id下的 amount
并且 a的id范圍 要在 c表和b表同時存在的id
sql 批量update in
--sqlserver
update a set *g_id=* from a,b where *_id = *_id;
--mysql
update a,b set *g_id=* from a,b where *_id = *_id;
--oracle
update a set *g_id=(select * from b where *_id = *_id) where exists (select 1 from b where *_id = *_id);
下面sql語句如何改為update語句:
update 生產計劃_明細 set 工費=AA.工費 FROM
(select 加工單號,sum(加工費合計) as 工費
from (select 加工費合計,對應加工單號,rcid from 交貨單_主表 ) tj, 生產計劃_明細 jhmx
WHERE jhmx.加工單號= tj.對應加工單號 and
* in(select max(rcid) from 生產計劃_明細)
and left(*,6)=left(*,6)
group by 加工單號) as AA
WHERE 生產計劃_明細.加工單號=AA.加工單號
sql語句update [表名] set [列明]=value where id in(1,2,3,4,5,6,7)
解決方案
1. 對傳入的參數進行特殊處理
動態的拼接SQL查詢語句
2.案例:
ListidList ;
// idList 處理List
// "id" 列名
string sql ="DELETE FROM target_table WHERE id IN "+ *reIn(idList,"id",conn );
// List處理UserList
// column_name 表中列名
// 數據庫連接 Connection
public string GetWhereIn(ListuserList,string column_name,Connection conn){
string[] ins = new string[*()];
for (int i = 0; i
轉載請注明出處華閱文章網 » sql語句updatein