简体   繁体   中英

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

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

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 .

Concerning the error: it is the first time I see the keyword table there. Try it as mentioned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM