3

尝试在这里做一些基本的数学运算,但无法使这件事起作用...我想根据一组标准比较计数值,然后将此计数值与相同的标准列表进行比较,但变量较少.

 SELECT Testa-TestB FROM(
    (SELECT count(loanflag) AS Testa FROM Data
      WHERE declinegroup="XYZ"
        AND orginalrating="A"
        AND score="724-747"
        AND mode="Open"
        AND delqdays>"0")

    (SELECT count(loanflag) AS Testb FROM Data
      WHERE declinegroup="XYZ"
        AND orginalrating="A"
        AND score="724-747"
        AND mode="Open"))

我想我在这方面工作太久了,我错过了一些简单的东西!

4

1 回答 1

2

在你想要直接减法

在 SQL Server 中

SELECT 
    (
        SELECT count(loanflag) 
        FROM Data
        WHERE 
            declinegroup="XYZ"
            AND orginalrating="A"
            AND score="724-747"
            AND mode="Open"
            AND delqdays>"0"
    ) - (
        SELECT count(loanflag) 
        FROM Data
        WHERE declinegroup="XYZ"
        AND orginalrating="A"
        AND score="724-747"
        AND mode="Open"
    )
;

或者,您可以先将值分配给变量,然后再减去它们

DECLARE testa int;
DECLARE testb int;

SET testa = (
        SELECT count(loanflag) 
        FROM Data
        WHERE 
            declinegroup="XYZ"
            AND orginalrating="A"
            AND score="724-747"
            AND mode="Open"
            AND delqdays>"0"
    );

SET testb = (
        SELECT count(loanflag) 
        FROM Data
        WHERE declinegroup="XYZ"
        AND orginalrating="A"
        AND score="724-747"
        AND mode="Open"
    );

Select (testa - testb);
于 2013-07-02T02:57:13.410 回答