SQL Query for Chi-SQUARE TEST [duplicate]

China☆狼群 提交于 2019-12-03 22:00:08

integer math, cast dimall.cnt to a decimal or numeric or do the following

/(dimall.cnt* 1.00)* (dimall.cnt * 1.00)

another example to explain what actually happens

select 3/2  -- output = 1, integer math, result is an integer

select 3/2.00  -- output = 1.50

Because you are already doing casts in your calculations, you might as well cast to float instead of bigint

 SELECT sessionnumber, sessioncount, timespent,
 (dim1.cnt * dim2.cnt * dim3.cnt)/(dimall.cnt*dimall.cnt) as expected
 FROM (SELECT sessionnumber, SUM(cast(cnt as float)) as cnt
 FROM d3
 GROUP BY sessionnumber) dim1 CROSS JOIN
 (SELECT sessioncount, SUM(cast(cnt as float)) as cnt
 FROM d3
 GROUP BY sessioncount) dim2 CROSS JOIN
 (SELECT timespent, SUM(cast(cnt as float)) as cnt
 FROM d3
 GROUP BY timespent) dim3 CROSS JOIN
 (SELECT SUM(cast(cnt as float)) as cnt FROM d3) dimall;

float has something like 16 digits of precision, so it should be adequate for counting any reasonable number of objects in the known universe.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!