我正在尝试使用SQL 2012基于以下数据生成特定字符串
| Id | Activity | Year |
|----|----------|------|
| 01 | AAAAA | 2008 |
| 01 | AAAAA | 2009 |
| 01 | AAAAA | 2010 |
| 01 | AAAAA | 2012 |
| 01 | AAAAA | 2013 |
| 01 | AAAAA | 2015 |
| 01 | BBBBB | 2014 |
| 01 | BBBBB | 2015 |
Run Code Online (Sandbox Code Playgroud)
结果需要看起来像;
| 01 | AAAAA | 2008-2010, 2012-2013, 2015 |
| 01 | BBBBB …Run Code Online (Sandbox Code Playgroud) 我有一个表test1有列数量.我想检索所有列的总和.所以我使用这样的SUM函数
SELECT SUM(cda.amount)FROM test cda
Run Code Online (Sandbox Code Playgroud)
如果表是空的,那么它给我null
等效的JPA代码如下
如果有n
public Double sumAmount()
{
Query query=entityManagerUtil.getQuery("SELECT SUM(cda.amount)FROM test cda");
Object result=query.getSingleResult();
return (Double)result;
}
Run Code Online (Sandbox Code Playgroud)
现在在我的控制器中,我将此金额添加到委托人;
Double total=prinicipal+daoImpl.sumAmount();
Run Code Online (Sandbox Code Playgroud)
作为sumAmount()返回,null所以我在这里添加NULLPOINTEREXCEPTIONprinicipal+daoImpl.sumAmount();
所以我想如果金额为空则返回0,所以尝试ISNULL和IFNULL都是这样的
SELECT ISNULL(SUM(cda.amount),0) FROM test cda
Run Code Online (Sandbox Code Playgroud)
但在这里它给了我以下错误
No data type for node: org.hibernate.hql.ast.tree.MethodNode
\-[METHOD_CALL] MethodNode: '('
+-[METHOD_NAME] IdentNode: 'ISNULL' {originalText=ISNULL}
Run Code Online (Sandbox Code Playgroud)
那么任何人都可以告诉我如何在JPA中正确使用ISNULL
到目前为止我的代码看起来像这样:
public class ThreeSort {
public static void main(String[] args) {
int num1 = Integer.parseInt(args[0]);
int num2 = Integer.parseInt(args[1]);
int num3 = Integer.parseInt(args[2]);
int x = Math.min(num1, num2);
int min = Math.min(x,num3);
int z = Math.max(num1, num2);
int max = Math.max(z, num3);
int a = 0;
int mid = 0;
while (mid >= min && mid <= max) {
mid = a;
}
System.out.println(min);
System.out.println(a);
System.out.println(max);
}
Run Code Online (Sandbox Code Playgroud)
我知道如何做最小和最大但我遇到中间问题.知道如何在没有条件语句的情况下这样做吗?