我在表帐户中有一个列,我已将其定义为双列。我想更新我正在调用的字段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
提交
取消