gpt4 book ai didi

java - 从结果集中检索结果 mysql java

转载 作者:行者123 更新时间:2023-11-29 06:53:05 26 4
gpt4 key购买 nike

在Java中。有谁知道如何从此查询中检索数据?我可以为简单的查询执行此操作,但我发现这种情况非常令人困惑:

SELECT (SELECT sum(r2.a) FROM R r2 WHERE year(r2.p) = 
'2015' and month(r2.p) < month(r1.p) ) AS Previous,
(SELECT sum(r3.a) FROM R r3 WHERE year(r3.p)
= '2015' and month(r3.p) > month(r1.p) ) AS Next,
(SELECT sum(r4.a) FROM R r4 WHERE year(r4.p)
= '2015' and month(r4.p) = month(r1.p) ) AS Curr
FROM R r1
WHERE YEAR(r1.pickupdate) = '2015';

最佳答案

使用声明的别名:AS Curr

ResultSet rs = preparedStatement.executeQuery();

while (rs.next()) {
Integer curr = rs.getInt("Curr");
// Do something here
}

关于java - 从结果集中检索结果 mysql java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46732145/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com