请教各位大虾SUM()函数怎样用
一个表tt,有两个字段tt1,tt2下面这条语句倒底有没有没错?
sele tt1,sum(case when tt2>500 then 1 else 0 end) from tt grou by tt1
CREATE CURSOR tt (tt1 c(2),tt2 n(3)) INSERT INTO TT VALUES ("A1",557) INSERT INTO TT VALUES ("A1",558) INSERT INTO TT VALUES ("A2",559) INSERT INTO TT VALUES ("A3",400) INSERT INTO TT VALUES ("A2",353) INSERT INTO TT VALUES ("A1",442) SELECT TT1,SUM(IIF(TT2>500,1,0)) AS TT2 FROM TT GROUP BY TT1 *或者 SELECT TT1,SUM(ICASE(TT2>500,1,0)) AS TT2 FROM TT GROUP BY TT1