我尝试ROUND()或不是所选的值。查询看起来像这样:
CASE Series
WHEN 'DMS' THEN ROUND(b.Quantity,0)
ELSE ROUND(b.Quantity,2)
END AS Quantity,
我也试过
IF(b.Series = 'DMS', ROUND(b.Quantity,0), ROUND(b.Quantity,2)) AS Quantity,
和
Series
每次我在最后得到2位小数。
当Quantity
是' DMS' Quantity
应该是一个整数(没有小数),在其他情况下Vertex
Country City Hotel
-------------- -------------- ---------------------------
ID Name ID Name ID Name
-------------- -------------- ---------------------------
#16:0 Italia #17:0 Roma #18:0 Residence Barberini
#18:1 Santa Prisca
Edges
In PartOf
--------------- -------------
From To From To
--------------- -------------
#18:0 #16:0 #17:0 #16:0
#18:0 #17:0
#18:1 #17:0
应该有两位小数。
答案 0 :(得分:0)
在结果集中,数据类型是整个结果集的列的属性。
对于结果集中的任何给定列,该列中每行的值必须具有相同的数据类型。
此查询的返回列的数据类型必须由服务器设置为 import java.util.Arraylist;
public class PrintPath
{
static ArrayList<String> paths = new ArrayList<String>();
public static long getUnique(int m, int n, int i, int j, String pathlist)
{
pathlist += ("(" + i + ", " + (j) + ") => ");
if(m == i && n == j)
{
paths.add(pathlist);
}
if( i > m || j > n)
{
return 0;
}
return getUnique(m, n, i+1, j, pathlist)+getUnique(m, n, i, j+1, pathlist);
}
public static void printPaths()
{
int count = 1;
System.out.println("There are "+paths.size() + " unique paths: \n");
for (int i = paths.size()-1; i>=0; i--)
{
System.out.println( "path " + count + ": " + paths.get(i));
count++;
}
}
public static void main(String args[])
{
final int start_Point = 1;
int grid_Height = 2;
int grid_Width = 2;
getUnique(grid_Height, grid_Width, start_Point, start_Point, "");
printPaths();
}
}
行,以便容纳所有可能的值。
我希望您所看到的内容实际上是正确的舍入,但最后会出现“意外”DECIMAL(11,2)
。
.00
会 - 可能 - 通过将所有内容都转换为字符串,为您提供看起来更像您期望的结果。
这显然是一些非常草率的类型处理,但这并不比预期不同类型出现在同一列中更加不合理......这是无法做到的。
更正确的解决方案是将它们作为两个不同的列返回,使用两个CAST(CASE ... END AS CHAR) AS Quantity
表达式或CASE
。
IF()
请注意,两个ROUND(IF(Series = 'DMS',b.Quantity,NULL),0) AS dms_quantity,
ROUND(IF(Series = 'DMS',NULL,b.Quantity),2) AS non_dms_quantity
测试都会计算相同的表达式并使其参数反转,而不是第二个使用!=且参数相同的参数,以便系列的NULL值(如果可能)由第二次测试。 (Anything!= NULL无法求值为true; IF()
的第三个参数用于FALSE和NULL结果。)