zhpsam109(孤寂无边),他们的主表编号不一样:)

解决方案 »

  1.   

    select min(序号),max(发送至),max(状态) from table where 发送至='李四' and 是否处理='否'
    group by 主表编号
      

  2.   

    bluelamb(bluelamb) 不对啊:(你这样只能取出串行的
      

  3.   

    try:
    select 序号 from 
    (select tbname.*,
    rank() over(partition by 发送至,主表编号 order by decode(状态,'串行',2,1)) rk
    from tbname where 发送至='李四' and 是否处理='否') t
    where t.rk=1;
      

  4.   

    select 序号 form (select distinct  主表编号,序号 from table where 发送至='李四')
    哈哈,这样应该可以取出来2-5-6!!!哈哈哈!
      

  5.   

    17:47:35 SQL> select * from tbname;      序号 发送至     主表编号   状态       是否处理
    ---------- ---------- ---------- ---------- ----------
             1 张三       00001      串行       是
             2 李四       00001      串行       否
             3 王五       00001      并行       否
             4 李四       00001      并行       否
             5 李四       00002      并行       否
             6 李四       00003      并行       否已选择6行。已用时间:  00: 00: 00.31
    17:47:42 SQL> select 序号 from 
    17:47:46   2  (select tbname.*,
    17:47:46   3  rank() over(partition by 发送至,主表编号 order by decode(状态,'串行',2,1) desc) rk
    17:47:46   4  from tbname where 发送至='李四' and 是否处理='否') t
    17:47:46   5  where t.rk=1;      序号
    ----------
             2
             5
             6已用时间:  00: 00: 00.15
    17:47:46 SQL>
      

  6.   

    bzszp(SongZip) 非常感谢!我试试看,好使结帖:)大家帮忙啊:)
      

  7.   

    就是比较厉害,我正在建立环境,等我在思考中,版主已经搞出来了,佩服!这个方法是很不错的,现在主要是对函数rank还是不够足够的熟练!
      

  8.   

    依次为 序号  主表编号 状态  是否处理  发送至  获取发送至为me的序号
    1  1 串行 1 me (已处理-舍弃)
    2  1 并行 0 yao(未处理-不属于me)
    3  1 串行 0 me (未处理-但上个序号姚没有处理,舍弃)
    4  2 串行 0 me (编号为2:属于新条且没有处理,记录下来)
    5  3 串行 1 yao(不属于me,已处理)
    7  4 串行 1 yao(不属于me,且已处理)
    8  4 并行 0 me (主表编号为4,上面序号为7的已经处理了,所以记录下来)
    9 3 并行 0 me (主表为3的记录,上面序号为5的已经处理,所以记录下来)所以最后记录为
    xh
    4
    8
    9
    版主那个好像还需要改一下:(可是我不会:(谢谢!
      

  9.   

    select xh from 
    (select test.*,
    rank() over(partition by wjqx,wjbh order by decode(status,'串行',2,1) desc) rk
     from test where wjqx='me' and cbx='0') t
     where t.rk=1;
    这是版主的sql
    依次为(xh,wjbh,status,cbx,wjqx)
    1  1 串行 1 me (已处理-舍弃)
    2  1 并行 0 yao(未处理-不属于me)
    3  1 串行 0 me (未处理-但上个序号姚没有处理,舍弃)
    4  2 串行 0 me (编号为2:属于新条且没有处理,记录下来)
    5  3 串行 1 yao(不属于me,已处理)
    7  4 串行 1 yao(不属于me,且已处理)
    8  4 并行 0 me (主表编号为4,上面序号为7的已经处理了,所以记录下来)
    9 3 并行 0 me (主表为3的记录,上面序号为5的已经处理,所以记录下来)
      

  10.   

    xh  wjbh   status   cbx    wjqx 
    1    1      串行      1      me //(已处理-舍弃)
    2    1      并行      0      yao//(未处理-不属于me)
    3    1      串行      0      me //(未处理-但上个序号姚没有处理,舍弃)
    4    2      串行      0      me //(编号为2:属于新条且没有处理,记录下来)
    5    3      串行      1      yao//(不属于me,已处理)
    7    4      串行      1      yao//(不属于me,且已处理)
    8    4      并行      0      me //(主表编号为4,上面序号为7的已经处理了,所以记录下来)
    9    3      并行      0      me //(主表为3的记录,上面序号为5的已经处理,所以记录下来)
    所以最后记录为
    xh
    4
    8
    9
    ========================================================
    采用 bzszp(SongZip) 的使用方式select xh from 
    (select test.*,
    rank() over(partition by wjqx,wjbh order by decode(status,'串行',2,1) desc) rk
     from test where wjqx='me' and cbx='0') t
     where t.rk=1;
    结果不对
      

  11.   

    2  1 并行 0 yao(未处理-不属于me) 这一条没有处理
                                     ~~~~~~~~~~~~~
    所以
    3  1 串行 0 me (未处理-但上个序号姚没有处理,舍弃)
      

  12.   

    就是对同一个的主表编号进行分组,在这个组中在根据是否处理字段和串并行字段来判断可以查看的记录.如:
    主编号为10000的组中有2条记录分别如下
    1 串行 未处理  发送至B人
    2 并行 未处理  发送至A人
    则此时2这条记录属于不可查看的如果记录为:
    1 并行 未处理  发送至B人
    2 并行 未处理  发送至A人
    则 1和2记录都可以查看如果记录为
    1 串行 已处理  发送至B人
    2 并行 未处理  发送至A人
    则2可查看,1不可查看如果记录为
    1 串行 已处理  发送至B人
    2 并行 未处理  发送至A人
    3 并行 未处理  发送至c人
    4 串行 未处理  发送至d人因为1已经处理,并且2和3都是并行,所以可见,4为串行
    所以2和3可见,1和4不可见
      

  13.   

    try:
    select xh from 
    (select test.*,
    rank() over(partition by wjqx,wjbh order by decode(status,'串行',2,1) desc) rk
     from test where cbx='0') t
     where t.rk=1;
      

  14.   

    XH         WJBH       STATUS     CBX        WJQX
    ---------- ---------- ---------- ---------- ----------
    1          1          串行       已处理     me
    2          1          并行       未处理     yao
    3          1          串行       未处理     me
    4          2          串行       未处理     me
    5          3          串行       已处理     yao
    7          4          串行       已处理     yao
    8          4          并行       已处理     me
    9          4          并行       未处理     yao
    10         3          并行       未处理     me=========================
    select xh from 
    (select test.*,
    rank() over(partition by wjqx,wjbh order by decode(status,'串行',2,1) desc) rk
     from test where cbx='未处理' AND wjqx='me') t
     where t.rk=1;
    ===================
    XH
    ----------
    3
    4
    10已选择3行。WJBH为1中xh为2的还没有处理,所以序号三不在其中,最终结果应该
    4
    10
      

  15.   

    为什么是降序?select xh from 
    (select test.*,
    rank() over(partition by wjqx,wjbh order by decode(status,'串行',2,1)) rk
     from test where cbx='未处理' AND wjqx='me') t
     where t.rk=1;
      

  16.   

    XH         WJBH       STATUS     CBX        WJQX
    ---------- ---------- ---------- ---------- ----------
    1          1          串行       已处理     me
    2          1          并行       未处理     yao
    3          1          串行       未处理     me
    4          2          串行       未处理     me
    5          3          串行       未处理     yao
    7          4          串行       已处理     yao
    8          4          串行       未处理     me
    9          4          并行       未处理     yao
    10         3          并行       未处理     me
    ================
    select xh from 
    (select test.*,
    rank() over(partition by wjqx,wjbh order by decode(status,'串行',2,1)) rk
     from test where cbx='未处理' AND wjqx='yao') t
     where t.rk=1;
    ===================已选择9行。XH
    ----------
    2
    5
    9xh为9的不应该存在啊,因为xh为8的未处理,主要他是串行不是并行,并行就是对的,但是如果是串行就错了.
      

  17.   

    select xh from 
    (select test.*,
    rank() over(partition by wjqx,wjbh order by decode(status,'串行',2,1)) rk
     from test where cbx='未处理' AND wjqx='me') t
     where t.rk=1 and xh not in (
    select xh from test where cbx='未处理' and status='并行'
    );
      

  18.   

    我这个语句的主要毛病是没有把同一个人有多个任务且需要选择出来的没有选择出来,如果把这个加上就可以了!SQL> select * from testa;NO                   SENDTO               MAINNO               STATUS               ISPROC
    -------------------- -------------------- -------------------- -------------------- ------
    11                   张三                 00001                串行                 1
    12                   李四                 00001                串行                 0
    13                   王五                 00001                并行                 0
    14                   李四                 00001                并行                 0
    15                   李四                 00002                并行                 0
    16                   李四                 00003                并行                 0
    1                    me                   1                    串行                 1
    2                    yao                  1                    并行                 0
    3                    me                   1                    串行                 0
    4                    me                   2                    串行                 0
    5                    yao                  3                    串行                 1
    7                    yao                  4                    串行                 1
    8                    me                   4                    并行                 0
    9                    me                   3                    并行                 014 rows selectedSQL> 
    SQL> select no from testa where mainno in (
      2  select mainno from
      3  (select testa.*,
      4  rank() over(partition by mainno,status order by mainno,status) rk
      5   from testa where isproc='0') t
      6   where t.rk=1 group by mainno having count(*)=1
      7   ) and isproc='0'and
      8    sendto='me'
      9  ;NO
    --------------------
    4
    9
    8SQL> 
    SQL> select no from testa where mainno in (
      2  select mainno from
      3  (select testa.*,
      4  rank() over(partition by mainno,status order by mainno,status) rk
      5   from testa where isproc='0') t
      6   where t.rk=1 group by mainno having count(*)=1
      7   ) and isproc='0'and
      8    sendto='李四'
      9  ;NO
    --------------------
    15
    16
      

  19.   

    SQL> 
    SQL> select no from testa where mainno in (
      2  select mainno from
      3  (select testa.*,
      4  rank() over(partition by mainno,status order by mainno,status) rk
      5   from testa where isproc='0') t
      6   where t.rk=1 group by mainno having count(*)=1
      7   ) and isproc='0'and
      8    sendto='李四'
      9  ;NO
    --------------------
    15
    16@@@@@@@@@@@@@@@少个12啊@@@@@@@@@@@@@@@@@@@@@
      

  20.   

    这个你再试一下,下面的语句专门用来处理这部分12的数据,你再对其他的数据试一下,我想应该没有多大问题了吧!
    select no from testa where mainno in (
    select mainno from 
    (select testa.*,
    rank() over(partition by mainno,status order by sendto) rk
     from testa where isproc='0') t
     where t.rk=1 group by mainno having count(*)=1 
     ) and isproc='0'and 
      sendto='me'
    union  
    select no from 
    (select testa.*,
    rank() over(partition by mainno,sendto order by status  ) rk
     from testa where isproc='0') t
     where t.rk>1 and sendto='me'
      

  21.   

    还是有问题啊,你把me改为yao就有问题
      

  22.   

    me和yao根据什么条件来进行呢,到底是选择哪个呢?因为这两个都是并行的!
    我感觉你应该说出一个规律来,这样写起来也好一些,要不针对不同的数据有不同的情况,写起来比较累!
      

  23.   

    NO                   SENDTO               MAINNO               STATUS               ISPROC
    -------------------- -------------------- -------------------- -------------------- ------
    11                   张三                 00001                串行                 1
    12                   李四                 00001                串行                 0
    13                   王五                 00001                并行                 0
    14                   李四                 00001                并行                 0
    15                   李四                 00002                并行                 0
    16                   李四                 00003                并行                 0
    1                    me                   1                    串行                 1
    2                    yao                  1                    并行                 0
    3                    me                   1                    串行                 0
    4                    me                   2                    串行                 0
    5                    yao                  3                    串行                 1
    7                    yao                  4                    串行                 1
    8                    me                   4                    并行                 0
    9                    me                   3                    并行                 0XH         WJBH       STATUS     CBX
    ---------- ---------- ---------- ----------
    11         4          并行       未处理
    1          1          串行       已处理
    2          1          并行       未处理
    3          1          并行       未处理
    4          2          串行       未处理
    5          3          串行       未处理
    7          4          串行       已处理
    8          4          串行       未处理
    9          4          并行       未处理
    10         3          并行       未处理
    12         1          串行       未处理这样吧,给出这样的数据.
    wjbh分组后  为1,2,3,4
    举个例子:
    wjbh为1的记录xh为
    1,2,3,12
    找到第一个未处理的记录xh,这里应该是2,看2的status是串行还是并行,如果是并行获取下一个记录,直到串行为止,如果是串行,则不再往下查找
    看wjbh为1的记录
    xh:1 已处理
    xh:2 并行  
    xh:3 并行
    xh:12 串行则显示记录
    xh
    ---
    2
    3
      

  24.   

    XH         WJBH       STATUS     CBX
    ---------- ---------- ---------- ----------
    11         4          并行       未处理
    1          1          串行       已处理
    2          1          并行       未处理
    3          1          并行       未处理
    4          2          串行       未处理
    5          3          串行       未处理
    7          4          串行       已处理
    8          4          串行       未处理
    9          4          并行       未处理
    10         3          并行       未处理
    12         1          串行       未处理这样吧,给出这样的数据.
    wjbh分组后  为1,2,3,4
    举个例子:
    wjbh为1的记录xh为
    1,2,3,12
    找到第一个未处理的记录xh,这里应该是2,看2的status是串行还是并行,如果是并行获取下一个记录,直到串行为止,如果是串行,则不再往下查找
    看wjbh为1的记录
    xh:1 已处理
    xh:2 并行  
    xh:3 并行
    xh:12 串行则显示记录
    xh
    ---
    2
    3
      

  25.   

    13:17:13 SQL> select * from tbname;      序号 发送至     主表编号   状态       是否处理
    ---------- ---------- ---------- ---------- ----------
             1 张三       00001      串行       1
             2 李四       00001      串行       0
             3 王五       00001      并行       0
             4 李四       00001      并行       0
             5 李四       00002      并行       0
             6 李四       00003      并行       0已选择6行。已用时间:  00: 00: 00.47
    13:17:20 SQL> 
    针对与这个数据,你想得到什么样的结果?