我在表帳戶中有一個列,我已將其定義為雙列。我想更新我正在調用的字段account_balance。這是我的代碼Query theQuery2 = currentSession.createSQLQuery("update account set account_balance = (select account_balance from account where telephone_number = ?4 AND nid_number = ?5) + ?6 where telephone_number = ?4 AND nid_number = ?5") ;theQuery2.setParameter(6, the_loss);theQuery2.setParameter(5, nid_number);theQuery2.setParameter(4, telephone_number);theQuery2.executeUpdate();這是mysql查詢update account set account_balance = (select account_balance where telephone_number = ?4 AND nid_number = ?5) + ?6我怎么能有這個查詢(select account_balance where telephone_number = ?4 AND nid_number = ?5)給我一個類型的值,double以便我添加準備好的值?6,它是 java 中的 double 類型?。
1 回答
繁星點點滴滴
TA貢獻1803條經驗 獲得超3個贊
這個查詢:
update account
set account_balance = (select account_balance where telephone_number = ?4 AND nid_number = ?5) + ?6
真的沒有意義。大概,您打算:
update account
set account_balance = account_balance + ?6
where telephone_number = ?4 and nid_number = ?5;
換句話說,過濾器繼續,update并且嵌套select是不必要的。
你真的不需要擔心類型。您將值作為參數傳遞,如果參數是數字類型(即支持加法),那么它將被添加到account_balance.
我會說應該使用numeric/ decimal(即定點值)而不是 double (浮點值)來存儲貨幣金額。
添加回答
舉報
0/150
提交
取消
