我试图得到两个计数,然后将这两个计数相比,以获得我计数的项目的比例。我在这里看到了这篇文章,并尝试了它。我的结果是错误的,没有错误的消息,只有错误的数字。我正在使用它SQL Server 20083 g# d1 G$ g& ?( I
这是我的代码:! w/ M8 c+ N) t; N% s
-- INTERNAL PEPPER REPORT--#####################################################################-- VARIABLE DECLARATION AND INITIALIZATIONDECLARE @SD DATETIMEDECLARE @ED DATETIMESET @SD = '2013-01-01'SET @ED = '2013-03-31'-- TABLE DECLARATION ##################################################DECLARE @TABLE1 TABLE(NUMERATOR INT,DENOMINATOR INT,RATIO INT)--#####################################################################-- WHAT GETS INSERTED INTO TABLE 1INSERT INTO @TABLE1SELECTA.NUM,A.DENOM,A.NUM/A.DENOMFROM(-- COLUMN SELECTION. TWO NUMBERS WILL REPRESENT A NUM AND A DENOMSELECT (SELECT COUNT(DRG_NO) FROM smsdss.BMH_PLM_PtAcct_V WHERE drg_no IN AND Adm_Date BETWEEN @SD AND @ED AND PLM_PT_ACCT_TYPE = 'I AS NUM, (SELECT COUNT(DRG_NO) FROM smsdss.BMH_PLM_PtAcct_V WHERE drg_no IN 066、067、068、069) AND Adm_Date BETWEEN @SD AND @ED AND Plm_Pt_Acct_Type = 'I AS DENOM)ASELECT NUMERATOR,DENOMINATOR,RATIOFROM @TABLE1计数正确生成并显示,但对于比率,我是0,不确定为什么会得到这个值。3 B( s1 W5 f! b8 a' _; C) j9 O
谢谢你, {) x+ w! A5 Y8 Q 9 g& p/ f) K( a 解决方案: 7 p; c9 x6 I" ?. L+ |
使用 SELECT A.NUM,A.DENOM,cast(A.NUM as float)/cast(A.DENOM as float) ) H( a- `5 t/ A2 F& i9 }SQL Server认为A.NUM / A.DENOM是int,因为A.NUM和A.DENUM是int