我有我在那里输入的数值这样的SQL学生考勤表:如何取出百分比SQL
Student_id total_classes class_attended
1 31 26
2 31 21
3 31 17
4 31 21
5 31 29
我想和1 林来计算student_id
出席百分比寻找如何框架SQL语句以上..
我有我在那里输入的数值这样的SQL学生考勤表:如何取出百分比SQL
Student_id total_classes class_attended
1 31 26
2 31 21
3 31 17
4 31 21
5 31 29
我想和1 林来计算student_id
出席百分比寻找如何框架SQL语句以上..
你只需要同生共划分了类的数量,然后乘以100:
SELECT student_id, ROUND(class_attended/total_classes*100) total FROM student
以上将返回以下结果:
+------------+-------+
| student_id | total |
+------------+-------+
| 1 | 84 |
| 2 | 68 |
| 3 | 55 |
| 4 | 68 |
| 5 | 94 |
+------------+-------+
是啊,它的工作... :-) – Varshaa
您可以使用一个选择查询,像
SELECT class_attended/total_classes AS AttendencePercentage 从考勤 WHERE student_id数据= '1'
是什么期望的输出? –
你知道如何编写一个基本的'select'语句吗?你知道如何计算一个百分比吗? – Blorgbeard
我是一个初学mysql的学习者...试图架构小型数据库,因此苦于查询... – Varshaa