[英]JDBC SQL SELECT query sum method not behaving properly
Hi I have a table with item and price as shown below 嗨我有一个项目和价格表如下所示
item price
ABC 5.0
DEF 6.0
and I am trying to execute it with the following query. 我试图用以下查询执行它。
select sum(sign(price)*ceiling(abs(price))) as price, item from product
Now when I execute this query staight away in the following way it works shows total as 11.0 in output for both item 现在,当我以下面的方式执行此查询时,它的工作在两个项目的输出中显示总计为11.0
statement.exectuteQuery("select sum(sign(price)*ceiling(abs(price))) as price, item from product")
But when I put query in string strangely it does not work and it gives null as output in price column 但是当我把奇怪的查询放入字符串时它不起作用,它在price列中给出null作为输出
String qry = "select sum(sign(price)*ceiling(abs(price))) as price, item from product";
statement.exectuteQuery(qry);
Please guide. 请指导。 Thanks in advance.
提前致谢。
select sum(sign(price)*ceiling(abs(price))) as price, item
from product
group by item
The aggregate functions such as sum
and count
will do the entire table, if not using a GROUP BY
. 如果不使用
GROUP BY
,则sum
和count
等聚合函数将执行整个表。
Concerning the error: it is the first time I see the keyword table
there. 关于错误:这是我第一次看到关键字
table
。 Try it as mentioned. 试试吧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.