create table test(
emp_id int not null ,
exam_date smalldatetime null ,
exam_result char(2) null
)字段说明:
emp_id 人员序号
exam_date 考核日期
exam_result 考核结果 (优秀='11')查询--连续两年考核为优秀的员工记录?
emp_id int not null ,
exam_date smalldatetime null ,
exam_result char(2) null
)字段说明:
emp_id 人员序号
exam_date 考核日期
exam_result 考核结果 (优秀='11')查询--连续两年考核为优秀的员工记录?
解决方案 »
- MYSQL两个表查询的问题
- Mysql在Redhat Linux 5 Server
- 咨询个问题,怎样对mysql4.026数据库进行优化
- MYSQL 插入问题 在线等
- array value must start with "{" or dimension information
- 求 gostgreSQL 的 链接库文件
- 安装问题很简单
- 如何将表A的数据移到表B中
- 【求助】 mysql 统计每三天的分娄为一条数据,要怎么写sql语句?
- 能不能每天凌晨删除指定表中前7天的所有数据
- 使用C/C++程序如果想Mysql中插入一条含有blob类型的数据记录?
- 执行了一个比较简单Mysql子查询,但是速度很慢,请各位高手帮忙看看问题所在和提供解决方法.
/*Table structure for table `test2` */DROP TABLE IF EXISTS `test2`;CREATE TABLE `test2` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`emp_id` int(11) NOT NULL,
`exam_date` datetime DEFAULT NULL,
`exam_result` char(2) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;/*Data for the table `test2` */insert into `test2`(`id`,`emp_id`,`exam_date`,`exam_result`) values (1,1,'2007-08-02 00:00:00','11'),
(2,6,'2007-11-02 00:00:00','10'),
(3,7,'2007-11-02 00:00:00','11'),
(4,1,'2006-08-02 00:00:00','11'),
(5,6,'2006-11-02 00:00:00','7'),
(6,7,'2006-11-02 00:00:00','11');查询语句 select a.emp_id from test2 a,test2 b
where a.emp_id = b.emp_id
and a.id != b.id
and year(a.exam_date) = year(b.exam_date)-1
and a.exam_result = '11';
结果:
query result(2 records)
emp_id
1
7