![](/img/trans.png)
[英]SQL Server - Update field in all table records, using a field from the same table and values from other table
[英]SQL Server: update a field with divided and multiplied values from other field on the same table
我想用來自以下表的值更新表中的字段:Transaction_Count字段:10 x 100例如,Transaction_Count值:3。那么計算應為:3:10 x 100 = 30
但是,當我運行代碼時,結果為0而沒有留下錯誤消息。 作為附加信息,我已經使用十進制(18,2)數據類型創建了挖掘表的Support字段。 如何獲得正確的結果,有人可以幫助我嗎?
這是我的代碼:
SQL = "Update Mining Set Support = Transaction_Count / 10 * 100"
Con.Execute (SQL)
您已經發現,SQL Server執行整數除法。 您可以重新排列操作數:
Update Mining
Set Support = (100 * Transaction_Count) / 10;
您的表情被評估為:
(Transaction_Count / 10) * 100 = (3 / 10) * 100
的3 / 10
是0
在SQL Server(和NOT 0.33333333),因為它確實整數除法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.