#!/bin/bash

source head.sh

echo '
    <div class="container mt-5">
        <h1 class="mb-4">三好学生列表</h1>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>年龄</th>
                    <th>分数</th>
                </tr>
            </thead>
            <tbody>
'
# 尝试从缓存读取
sql="select jx_stu.id, jx_stu.name, jx_stu.age, avg(jx_score.score) from jx_score join jx_stu on jx_score.stuId=jx_stu.id group by stuId having avg(score) > 90;"
source cache.sh

for stu in ${stuList[@]}; do
  # 获取学号、姓名、班级、年龄
  id=$(echo $stu | awk -F "@" '{print $1}')
  name=$(echo $stu | awk -F "@" '{print $2}')
  age=$(echo $stu | awk -F "@" '{print $3}')
  class=$(echo $stu | awk -F "@" '{print $4}')
  echo "
                  <tr>
                      <td>$id</td>
                      <td>$name</td>
                      <td>$age</td>
                      <td>$class</td>
                  </tr>
  "
done
echo '
            </tbody>
        </table>
    </div>
    
    <!-- 引入Bootstrap的JavaScript文件，用于一些表格交互效果 -->
    <script src="/static/js/bootstrap.min.js"></script>
</body>
</html>
'
