gpt4 book ai didi

mysql - 将多个表中的内容检索到单个表中的模板是什么

转载 作者:行者123 更新时间:2023-11-29 17:44:06 25 4
gpt4 key购买 nike

如何通过从两个表中搜索value(Updatedby)将不同表的数据合并到一个表中并显示在JSP页面中?

添加更多信息:我的 table1 名称是 testraildumptable我的 table2 名称是时间表

 <tr>
<th style="width: 30$">ID</th>
<th style="width: 30$">Created By</th>
<th style="width: 30$">Estimate time</th>
<th style="width: 30$">Timesheet time</th>
<th style="width: 30%">Updated By</th>
</tr>
<%
try
{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/testraildump","roo t","root");
String Query="SELECT id, createdby, estimatetime, executionhours, updatedby from testraildumptable inner join timesheet on testraildumptable.updatedby = timesheet.updatedby where updatedby='"+request.getParameter("search")+"'";


Statement stm=conn.createStatement();
ResultSet rs=stm.executeQuery(Query);
while(rs.next())
{
%>
<tr>
<td><%=rs.getString("id")%></td>
<td><%=rs.getString("createdby")%></td>
<td><%=rs.getString("estimatetime")%></td>
<td><%=rs.getString("executionhours")%></td>
<td><%=rs.getString("updatedby")%></td>

</tr>
<%
}
}

添加更多信息:我的 table1 名称是 testraildumptable我的 table2 名称是时间表

最佳答案

对于控制台中的错误:“字段列表中的“updatedby”列不明确”

因为表testraildumptabletimesheet都有一个名为updatedby的列属性,所以在查询时,不知道选择哪一个。

您可以按如下方式更新查询sql:

String Query="SELECT t1.id, t1.createdby, t1.estimatetime, t1.executionhours, t1.updatedby from testraildumptable t1 inner join timesheet t2 on t1.updatedby = t2.updatedby where t1.updatedby='"+request.getParameter("search")+"'";

关于mysql - 将多个表中的内容检索到单个表中的模板是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49880600/

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