我有一個tsql查詢爲百分比計算,如果結果大於1,它計算得很好,但當它小於1時返回0。我的計算是這樣的:使用計算不返回小於1的計算的TSQL查詢
create table dbo.#temptable (
total_sold int null,
#_in_ny int null,
percent_in_ny decimal(18,2)null
) on [primary]
insert into dbo.#temptable
select count(t.booknum) as totalsold, t.#_in_ny, 100 * t.#_in_ny/count(t.booknum)
from mytable t
這給了我:
total ny sales %sales in ny
650 4 0 ---- this should show up as 0.61 since 4 is .61% of 650
在恆力sql服務器中使用float來做小數點除法嗎? –