删除一段时间的老师发布的任务

1.删除老师发布的讨论任务,发布时间是2015-5-8,2015-5-9

(1)任务表中存放着资源活动的id,没有存放资源活动的类型,所以要关联才能查询出讨论活动的任务

(2)mysql中不能drop 数据where条件的子查询使用本表查询,所以考虑使用mysql的迭代器(之前使用过oracle的迭代器),但是mysql中没有迭代器,所以只能临时表存放数据。

(3)临时表用完后,要删除临时表

 

具体操作步骤:

(1).满足发布时间在2015-5-8,2015-5-9的tccsq001老师发布的讨论任务的id,存放在临时表tmp_table_shiyanban中。

CREATE TEMPORARY TABLE tmp_table_shiyanban SELECT gm_task.id FROM gm_task,gm_activity_resource WHERE gm_task.activity_id=gm_activity_resource.id AND 

 gm_task.teacher_id=(SELECT id FROM gm_user WHERE u_num='tccsq001') 

 AND gm_activity_resource.type=4 

 AND DATE_FORMAT(gm_task.create_time,'%Y-%m-%d') IN  

('2015-05-10','2015-05-11')

 (2)删除老师的任务

         DELETE FROM gm_task WHERE id IN (SELECT * FROM  tmp_table_shiyanban)

 (3)删除任务对应的学生任务

         DELETE FROM gm_user_tasks_list WHERE task_id IN (SELECT * FROM  tmp_table_shiyanban)

 (4)删除临时表

          DROP TEMPORARY TABLE tmp_table_shiyanban

 

2.更新老师发布任务的资源互动名称

SELECT * FROM gm_task,gm_activity_resource WHERE gm_task.activity_id=gm_activity_resource.id AND 

 gm_task.teacher_id=(SELECT id FROM gm_user WHERE u_num='tccsq001') 

 AND gm_activity_resource.type=4 

 AND DATE_FORMAT(gm_task.create_time,'%Y-%m-%d') IN  

('2015-04-10','2015-04-01')

 

CREATE TEMPORARY TABLE tmp_table_shiyanban SELECT gm_task.id FROM gm_task,gm_activity_resource WHERE gm_task.activity_id=gm_activity_resource.id AND 

 gm_task.teacher_id=(SELECT id FROM gm_user WHERE u_num='tccsq001') 

 AND gm_activity_resource.type=4 

 AND DATE_FORMAT(gm_task.create_time,'%Y-%m-%d') IN  

('2015-05-10','2015-05-11')

 

 

SELECT * FROM gm_task,gm_activity_resource WHERE gm_task.activity_id=gm_activity_resource.id AND 

 gm_task.teacher_id=(SELECT id FROM gm_user WHERE u_num='tccsq001') 

 AND gm_activity_resource.type=4 

 AND DATE_FORMAT(gm_task.create_time,'%Y-%m-%d') IN  

('2015-05-10','2015-05-11')

 

SELECT * FROM gm_activity_resource WHERE id='824b3b11-8c86-4295-acc9-4e6770756410';

 

UPDATE gm_activity_resource SET NAME="OK1"  WHERE id='824b3b11-8c86-4295-acc9-4e6770756410';

 

SELECT * FROM gm_user_tasks_list WHERE activity_id ='824b3b11-8c86-4295-acc9-4e6770756410'

 

UPDATE gm_user_tasks_list SET NAME='ok1' WHERE activity_id ='824b3b11-8c86-4295-acc9-4e6770756410'

 

 

 

 

 

 

你可能感兴趣的:(时间)