现在的位置: 首页 > 综合 > 正文

分页加union all

2013年08月30日 ⁄ 综合 ⁄ 共 598字 ⁄ 字号 评论关闭

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

 

这个sql是我写的最复杂的了。欢迎指正

抱歉!评论已关闭.