针对筛选结果的二次筛选

表1:table1
字段:日期 时间 工号 姓名
如下:
日期 时间 工号 姓名
20160505 093022 0002 张三
20160505 093025 0003 张四
20160505 093027 0002 张三
20160505 093030 0004 张五
20160505 093035 0002 张三
20160505 093040 0004 张五
20160505 093045 0002 张三

表2:他table2
字段: 工号 姓名 岗位 技能 部门
如下
工号 姓名 岗位 技能 部门
0002 张三 外拓 营销 一部
0003 张四 内勤 售后 三部
0004 张五 外拓 营销 二部

第一步:把表2中的岗位、技能、部门插入到表1中
第二步:针对插入新数据的表1进行数据筛选
筛选要求:在时间093000-093045 时段内 去掉重复人员后 外勤人员几个? 内勤人员几个? 营销技能几个?售后技能几个? 一部几人?二部几人?

首先给table1增加3个字段:gw : 岗位、jn : 技能、bm : 部门。都是可为空的。
设number:工号。
update table1 set gw='外拓',jn='营销' bm='一部' where number='0002'
update table1 set gw='外拓',jn='营销' bm='二部' where number='0004'
update table1 set gw='内勤',jn='售后' bm='一部' where number='0003'

再然后,
select distinct name from table1 where jn='营销'
select distinct name from table1 where jn='售后'
select distinct name from table1 where gw='内勤'
select distinct name from table1 where gw='外拓'
select distinct name from table1 where bm='一部'
select distinct name from table1 where bm='二部'
这六个都有行数,有几行就是有几个