以下是数据库表:
//考勤记录学生表
create table `att_student_attendance` (
`student_attend_id` bigint(20) not null auto_increment,
`student_id` int(11) not null comment '学生id',
`card_num` varchar(20) not null comment '校园卡号',
`sign_time` datetime not null comment '签到时间',
`opt_type` tinyint(4) not null comment '进校/离校: 1:早上到校 2:中午离校 3:下午到校 4:下午离校 5:晚上到校 6:晚上离校',
`attend_type` int(11) default null comment '所属考勤类别',
`result` int(11) default null comment '考勤结果:1:正常 2:早退 3:迟到 4:请假 5:未刷卡',
primary key (`student_attend_id`),
key `fk_fk_reference_5` (`attend_type`),
key `fk_fk_reference_7` (`student_id`),
constraint `fk_fk_reference_5` foreign key (`attend_type`) references `att_attendance_type` (`attend_type_id`),
constraint `fk_fk_reference_7` foreign key (`student_id`) references `edu_student` (`student_id`)
) engine=innodb auto_increment=53 default charset=utf8 comment='考勤记录学生表';
//学生表
create table `edu_student` (
`student_id` int(11) not null auto_increment,
`name` varchar(20) not null comment '姓名',
`bind_card` tinyint(1) not null default '1' comment '是否校园卡用户',
`card_num` varchar(20) default null comment '校园卡卡号',
primary key (`student_id`)
) engine=innodb auto_increment=36 default charset=utf8 comment='学生表';
//考勤类别表
create table `att_attendance_type` (
`attend_type_id` int(11) not null auto_increment,
`attendance_id` int(11) default null comment '考勤设置id',
`opt_type` int(11) default null comment '进校离校: 1:早上到校 2:中午离校 3:下午到校 4:下午离校 5:晚上到校 6:晚上离校',
`name` varchar(50) default null comment '考勤类别名称',
`start_time` time default null comment '开始时间',
`end_time` time default null comment '结束时间',
primary key (`attend_type_id`),
key `fk_reference_50` (`attendance_id`),
constraint `fk_reference_50` foreign key (`attendance_id`) references `att_attendance_set` (`attend_set_id`)
) engine=innodb auto_increment=10 default charset=utf8 comment='考勤类别表';//考勤设置表
create table `att_attendance_set` (
`attend_set_id` int(11) not null auto_increment,
`school_id` int(11) default null comment '所属学校',
`target` tinyint(4) default null comment '目标类型:1:老师 2:学生',
`type` int(11) default null comment '考勤方式',
`attend_range` int(11) default null comment '1:周一至周五 2:周六 3:周天',
`start_off` smallint(6) not null default '0' comment '迟到时间范围',
`end_off` smallint(6) not null default '0' comment '早退时间范围',
`need_notice` tinyint(1) not null default '0' comment '是否发送考勤消息',
primary key (`attend_set_id`)
) engine=innodb auto_increment=9 default charset=utf8 comment='考勤设置表';
//学校表
create table `edu_school` (
`school_id` int(11) not null auto_increment,
`school_name` varchar(50) not null comment '学校名称',
`province_id` smallint(6) not null comment '省',
`city_id` smallint(6) not null comment '市',
`district_id` smallint(6) not null comment '区',
primary key (`school_id`)
) engine=innodb auto_increment=37 default charset=utf8 comment='学校表';图1:
图2:
请大家帮忙看看下面这两个问题如何写sql语句呢?
第一个问题:
请看图1,如何写sql或者存储过程来显示出图1的列呢?
序号,姓名,校园卡号,早上到校,中午离校,下午到校,下午离校,晚上到校,晚上离校第二个问题:如图1,在总计那行,如何用sql查询统计出:(刷卡多少/未刷多少/异常多少?) 例如查询后统计出:刷卡20/未刷10/异常5现在有五种状态:正常、早退、迟到、请假、未刷卡正常、早退、迟到,这三者加起来的量属于刷卡的数量 相当于上面的:刷卡20请假、未刷卡属于未刷的数量 相当于上面的:未刷10早退、迟到 属于异常的数量 相当于:异常5
//考勤记录学生表
create table `att_student_attendance` (
`student_attend_id` bigint(20) not null auto_increment,
`student_id` int(11) not null comment '学生id',
`card_num` varchar(20) not null comment '校园卡号',
`sign_time` datetime not null comment '签到时间',
`opt_type` tinyint(4) not null comment '进校/离校: 1:早上到校 2:中午离校 3:下午到校 4:下午离校 5:晚上到校 6:晚上离校',
`attend_type` int(11) default null comment '所属考勤类别',
`result` int(11) default null comment '考勤结果:1:正常 2:早退 3:迟到 4:请假 5:未刷卡',
primary key (`student_attend_id`),
key `fk_fk_reference_5` (`attend_type`),
key `fk_fk_reference_7` (`student_id`),
constraint `fk_fk_reference_5` foreign key (`attend_type`) references `att_attendance_type` (`attend_type_id`),
constraint `fk_fk_reference_7` foreign key (`student_id`) references `edu_student` (`student_id`)
) engine=innodb auto_increment=53 default charset=utf8 comment='考勤记录学生表';
//学生表
create table `edu_student` (
`student_id` int(11) not null auto_increment,
`name` varchar(20) not null comment '姓名',
`bind_card` tinyint(1) not null default '1' comment '是否校园卡用户',
`card_num` varchar(20) default null comment '校园卡卡号',
primary key (`student_id`)
) engine=innodb auto_increment=36 default charset=utf8 comment='学生表';
//考勤类别表
create table `att_attendance_type` (
`attend_type_id` int(11) not null auto_increment,
`attendance_id` int(11) default null comment '考勤设置id',
`opt_type` int(11) default null comment '进校离校: 1:早上到校 2:中午离校 3:下午到校 4:下午离校 5:晚上到校 6:晚上离校',
`name` varchar(50) default null comment '考勤类别名称',
`start_time` time default null comment '开始时间',
`end_time` time default null comment '结束时间',
primary key (`attend_type_id`),
key `fk_reference_50` (`attendance_id`),
constraint `fk_reference_50` foreign key (`attendance_id`) references `att_attendance_set` (`attend_set_id`)
) engine=innodb auto_increment=10 default charset=utf8 comment='考勤类别表';//考勤设置表
create table `att_attendance_set` (
`attend_set_id` int(11) not null auto_increment,
`school_id` int(11) default null comment '所属学校',
`target` tinyint(4) default null comment '目标类型:1:老师 2:学生',
`type` int(11) default null comment '考勤方式',
`attend_range` int(11) default null comment '1:周一至周五 2:周六 3:周天',
`start_off` smallint(6) not null default '0' comment '迟到时间范围',
`end_off` smallint(6) not null default '0' comment '早退时间范围',
`need_notice` tinyint(1) not null default '0' comment '是否发送考勤消息',
primary key (`attend_set_id`)
) engine=innodb auto_increment=9 default charset=utf8 comment='考勤设置表';
//学校表
create table `edu_school` (
`school_id` int(11) not null auto_increment,
`school_name` varchar(50) not null comment '学校名称',
`province_id` smallint(6) not null comment '省',
`city_id` smallint(6) not null comment '市',
`district_id` smallint(6) not null comment '区',
primary key (`school_id`)
) engine=innodb auto_increment=37 default charset=utf8 comment='学校表';图1:
图2:
请大家帮忙看看下面这两个问题如何写sql语句呢?
第一个问题:
请看图1,如何写sql或者存储过程来显示出图1的列呢?
序号,姓名,校园卡号,早上到校,中午离校,下午到校,下午离校,晚上到校,晚上离校第二个问题:如图1,在总计那行,如何用sql查询统计出:(刷卡多少/未刷多少/异常多少?) 例如查询后统计出:刷卡20/未刷10/异常5现在有五种状态:正常、早退、迟到、请假、未刷卡正常、早退、迟到,这三者加起来的量属于刷卡的数量 相当于上面的:刷卡20请假、未刷卡属于未刷的数量 相当于上面的:未刷10早退、迟到 属于异常的数量 相当于:异常5
参考一下这个贴子的提问方式http://bbs.csdn.net/topics/320211382
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
--考勤设置表
insert into att_attendance_set values(1,1,2,1,1,1,1,1);--考勤类别表
INSERT into att_attendance_type VALUES(1,1,0,'早上到校','07:59:50','8:59:50');
INSERT into att_attendance_type VALUES(2,1,1,'中午离校','12:00:50','12:59:50');
INSERT into att_attendance_type VALUES(3,1,0,'下午到校','13:59:50','14:59:50');
INSERT into att_attendance_type VALUES(4,1,1,'下午离校','16:59:50','17:59:50');
INSERT into att_attendance_type VALUES(5,1,0,'晚上到校','20:59:50','21:59:50');
INSERT into att_attendance_type VALUES(6,1,1,'晚上离校','19:59:50','20:59:50');
--考勤记录学生表
insert into att_student_attendance values(1,1,'cm123456','2014-07-29 01:00:51',0,1,1);
insert into att_student_attendance values(2,1,'cm123456','2014-07-30 01:00:51',1,2,2);
insert into att_student_attendance values(3,1,'cm123456','2014-07-28 01:00:51',0,3,3);
insert into att_student_attendance values(4,1,'cm123456','2014-07-27 01:00:51',1,4,4);
insert into att_student_attendance values(5,1,'cm123456','2014-07-26 01:00:51',0,5,5);
insert into att_student_attendance values(6,1,'cm123456','2014-07-24 01:00:51',1,6,3);--学校表
insert into edu_school values(1,'北京小学',1,1,1);--学生表
insert into edu_student values(1,'小名',1,1,'cm123456');
insert into edu_student values(2,'小红,1,1,'cm663456');
insert into edu_student values(3,'小花',1,1,'cm773456');要的效果图如下排列: 看能不能用mysql查询显示?
序号 姓名 校园卡号 早上到校 中午离校 下午到校 下午离校 晚上到校 晚上离校
1 小名 cm123456 正常 早退 未刷卡 迟到 正常 请假