1

我想在 select 语句中使用 if 运算符,使用 executeQuery 命令。就像是:

def tmpRec = BankStatement.executeQuery("select   SUM(IF(operation='CREDIT',cashAmount,-1*cashAmount)) from BankStatement group by portfolio,currency,code")

go 但 IF 运算符不起作用。

谢谢你

4

1 回答 1

1

虽然我不知道 Groovy SQL,但在大多数 DBMS 中,CASE 语句用作条件语句。也许以下方法会起作用:

def tmpRec = BankStatement.executeQuery("select SUM(CASE WHEN operation='CREDIT' THEN cashAmount ELSE (-1*cashAmount) END) from BankStatement group by portfolio,currency,code")
于 2012-10-29T18:08:28.027 回答