【发布时间】:2021-06-10 16:32:54
【问题描述】:
我有两个存储学生数据的表 - students 表和 student_session 表
学生表结构
CREATE TABLE IF NOT EXISTS `students` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`parent_id` int(11) NOT NULL,
`admission_no` varchar(100) DEFAULT NULL,
`roll_no` varchar(100) DEFAULT NULL,
`admission_date` date DEFAULT NULL,
`firstname` varchar(100) DEFAULT NULL,
`lastname` varchar(100) DEFAULT NULL,
`rte` varchar(20) DEFAULT NULL,
`image` varchar(100) DEFAULT NULL,
`mobileno` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`is_active` varchar(255) DEFAULT 'yes',
`disable_at` date NOT NULL,
`created_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
student_session 表结构
CREATE TABLE IF NOT EXISTS `student_session` (
`id` int(11) NOT NULL,
`session_id` int(11) DEFAULT NULL,
`student_id` int(11) DEFAULT NULL,
`class_id` int(11) DEFAULT NULL,
`section_id` int(11) DEFAULT NULL,
`route_id` int(11) NOT NULL,
`hostel_room_id` int(11) NOT NULL,
`vehroute_id` int(10) DEFAULT NULL,
`transport_fees` float(10,2) NOT NULL DEFAULT 0.00,
`fees_discount` float(10,2) NOT NULL DEFAULT 0.00,
`is_active` varchar(255) DEFAULT 'no',
`created_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
现在,我已经能够使用此查询获得班级中的学生总数
public function Gettotalstudents($session_id, $section_id, $class_id)
{
$this->db->select('student_id');
$this->db->where('session_id', $session_id);
$this->db->where('section_id', $section_id);
$this->db->where('class_id', $class_id);
return $this->db->count_all_results('student_session');
}
但是,也有一些学生因不交学费而被禁用或永久离开学校。 问题是由于这些学生只是被禁用而不是被删除,因此查询仍然将他们计入活跃学生。
现在,我想将残疾学生排除在统计范围之外。
注意 - 在学生表结构中,'is_active' 行存储学生是活跃还是禁用的数据。 “是”表示学生处于活动状态,“否”表示学生已被禁用。
我该怎么做?
【问题讨论】:
标签: php mysql codeigniter