我试图获得两个计数,然后将这两个计数相除以获得我正在计数的项目的比率。我在这里看到了这篇文章并尝试了。我的结果出现错误,没有错误消息,只是数字不正确。我正在使用 SQL-Server 2008
这是我的代码:
-- INTERNAL PEPPER REPORT
--#####################################################################
-- VARIABLE DECLARATION AND INITIALIZATION
DECLARE @SD DATETIME
DECLARE @ED DATETIME
SET @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 1
INSERT INTO @TABLE1
SELECT
A.NUM, A.DENOM, A.NUM/A.DENOM
FROM
(
-- COLUMN SELECTION. TWO NUMBERS WILL REPRESENT A NUM AND A DENOM
SELECT
(SELECT COUNT(DRG_NO)
FROM smsdss.BMH_PLM_PtAcct_V
WHERE drg_no IN (061,062,063,064,065,066)
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 (061,062,063,064,065,066,067,068,069)
AND Adm_Date BETWEEN @SD AND @ED
AND Plm_Pt_Acct_Type = 'I')
AS DENOM
)A
SELECT NUMERATOR, DENOMINATOR, RATIO
FROM @TABLE1
计数得到正确生成和显示,但是对于比率我得到 0 并且不确定我为什么得到这个。
谢谢你,