1

我无法在 Interbase 中执行以下 SQL:我收到以下错误:

第 1 行出错尝试执行未准备好的动态 SQL 语句

SQL:

SELECT CASE
   WHEN kl='K' THEN (SUM(DB)-SUM(CR))
   WHEN kl='L' THEN (SUM(CR)-SUM(DB))
   END AS Saldo
FROM  Table1
GROUP BY KL

对于以Table1这种方式定义的:

Column name   Data type
------------  ------------
KL            varchar(1)
DB            int
CR            int

然而它在SQL 小提琴中工作

以下也有效!

SELECT CASE 
   WHEN kl='K' THEN 1
   WHEN kl='L' THEN 2
   END as Saldo
FROM  Table1
Group By KL
4

1 回答 1

0

Found It!

SELECT Sum(CASE
       WHEN kl='K' THEN db
       WHEN kl='L' THEN cr
       END )
      -Sum(CASE
       WHEN kl='K' THEN CR
       WHEN kl='L' THEN DB
       END )

 FROM  Table1
Group By KL
于 2012-10-17T07:41:35.930 回答