You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
const pool = require('../db');
|
|
|
|
|
|
|
|
async function get_descend_Ranking(req, res) {
|
|
|
|
try {
|
|
|
|
const connection = await pool.getConnection();
|
|
|
|
const [ranking] = await connection.query('SELECT student_name, student_id, score FROM students ORDER BY score DESC');
|
|
|
|
connection.release();
|
|
|
|
res.json(ranking);
|
|
|
|
} catch (error) {
|
|
|
|
res.status(500).send({ error: '无法获取排名' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async function get_ascend_Ranking(req, res) {
|
|
|
|
try {
|
|
|
|
const connection = await pool.getConnection();
|
|
|
|
const [ranking] = await connection.query('SELECT student_name, student_id, score FROM students ORDER BY score ASC');
|
|
|
|
connection.release();
|
|
|
|
res.json(ranking);
|
|
|
|
} catch (error) {
|
|
|
|
res.status(500).send({ error: '无法获取排名' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = { get_ascend_Ranking, get_descend_Ranking };
|