pat_point,pat_task,pat_taskdetail 三个表,我要做修改任务
任务关联到任务详细
任务详细中有 关联point
修改任务 就要修改任务包含的点。
所以要列出所有 不在其它任务中的 点,并且属于本任务的点要在checkbox打钩,并且属于本任务的点要在前几页显示。
select P.P_ID,P.P_GID,P.P_NAME,P.P_SERIALNUM,P.P_TYPE,P.P_ADDR,P.P_CTTIME,
P.P_REM,h.has from pat_point P ,(select 1 as has) h where p_id in (
select td_pid from pat_taskDetail
where td_tid = 11
)
union all
SELECT P.P_ID,P.P_GID,P.P_NAME,P.P_SERIALNUM,P.P_TYPE,P.P_ADDR,P.P_CTTIME,
P.P_REM,h.has
FROM PAT_POINT P,(select 0 as has) h where p_id not in (
select td_pid from pat_taskDetail
where td_tid in(
select t_id from pat_task
where t_patid = 2
)
)
limit 2,3
任务关联到任务详细
任务详细中有 关联point
修改任务 就要修改任务包含的点。
所以要列出所有 不在其它任务中的 点,并且属于本任务的点要在checkbox打钩,并且属于本任务的点要在前几页显示。
select P.P_ID,P.P_GID,P.P_NAME,P.P_SERIALNUM,P.P_TYPE,P.P_ADDR,P.P_CTTIME,
P.P_REM,h.has from pat_point P ,(select 1 as has) h where p_id in (
select td_pid from pat_taskDetail
where td_tid = 11
)
union all
SELECT P.P_ID,P.P_GID,P.P_NAME,P.P_SERIALNUM,P.P_TYPE,P.P_ADDR,P.P_CTTIME,
P.P_REM,h.has
FROM PAT_POINT P,(select 0 as has) h where p_id not in (
select td_pid from pat_taskDetail
where td_tid in(
select t_id from pat_task
where t_patid = 2
)
)
limit 2,3
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。
1;PRIMARY;<derived2>;system;<NULL>;<NULL>;<NULL>;<NULL>;1;;
1;PRIMARY;P;ALL;<NULL>;<NULL>;<NULL>;<NULL>;33;Using where;
3;DEPENDENT SUBQUERY;pat_taskDetail;index_subquery;TD_TID,TD_PID;TD_PID;5;func;1;Using where;
2;DERIVED;<NULL>;<NULL>;<NULL>;<NULL>;<NULL>;<NULL>;<NULL>;No tables used;
4;UNION;<derived5>;system;<NULL>;<NULL>;<NULL>;<NULL>;1;;
4;UNION;P;ALL;<NULL>;<NULL>;<NULL>;<NULL>;33;Using where;
6;DEPENDENT SUBQUERY;pat_taskDetail;index_subquery;TD_PID;TD_PID;5;func;2;Using where;
7;DEPENDENT SUBQUERY;pat_task;unique_subquery;PRIMARY,T_PATID;PRIMARY;4;func;1;Using where;
5;DERIVED;<NULL>;<NULL>;<NULL>;<NULL>;<NULL>;<NULL>;<NULL>;No tables used;
<NULL>;UNION RESULT;<union1,4>;ALL;<NULL>;<NULL>;<NULL>;<NULL>;<NULL>;;