0

您好,我正在编写一个SQL从多个表中获取数据并从结果集中检索数据的查询,我们需要rs.getString(1)从相应的表中进行操作,但对我而言,数据来自多个表。

你能告诉我怎么做吗?

为了便于参考,我将我的SQL查询包括在内

select EID,sport,emich_email, lastname,firstname,numtodsinterval(sum(
  extract(day from dd) * (24 * 60 * 60)
    + extract(hour from dd) * (60 * 60)
    + extract(minute from dd) * 60
    + extract(second from dd)
  ), 'SECOND') as total_hours
from (
  select scans.emich_email,EID,lastname,firstname,Sport, sign_out - sign_in as dd from scans INNER JOIN student_details ON scans.emich_email=student_details.emich_email INNER JOIN Athlete ON student_details.EID=Athlete.EID)
group by emich_email,EID,lastname,firstname,sport;
4

1 回答 1

0

您应该能够使用别名恢复列,例如

select name as the_name, surname as the_surname from employees where...

然后ResultSet通过别名从您的每一列中恢复

String myName = rs.getString("the_name");
String mySurname = rs.getString("the_surname");
...

如果你仔细选择你的别名,你可以试试这个:

select table1.xxx as table1_xxx, table1.yyy as table1_yyy, ...., table3.zzz as table3_zzz from table1 join table2 on ...

我不知道这是否是您需要的,但也许这对您有用,或者至少是更易读的 java 代码

于 2014-05-14T14:23:00.570 回答