我正在开发一个时间表生成器,每个团队都可以与其他团队进行比赛。我的数据库表和我需要的输出如下所示,

到目前为止我尝试过的是
 <%
    ResultSet rsteams = clmmodel_database.selectQuery("select count(ct.teamid) as teamcount, teamid,teamname from clm_team ct");
    while(rsteams.next()){
       int teamcount = rsteams.getInt("teamcount"); 
       int n = teamcount - 1;
       int numofmatches  = n*(n+1)/2; 
    %>
    <h1>Team Count = <%out.print(teamcount);%></h1>
    <h1>Number of Matches = <%out.print(numofmatches);%></h1>
    <table>
    <%for(int i =0;i<n;i++){%>
    <tr>
      //Here I need to display the matches row by row  
    </tr>
    <%}%>
    </table>
    <%}%>
它检索团队计数和要进行的比赛的数量。请帮助我。