字段1   字段2   字段3   字段4    字段5  字段6
  A      B      C      001      1     11
  A      B      C      002      2     22
  A      B      C      003      3     33
  A      B      D      004      4     44
  A      B      D      005      5     55
  A      B      D      006      6     66select 字段1,字段2,字段3....from 表 
where (条件1 or 条件2) and 条件3 and 条件4 条件1=字段1,字段2,字段3 相同的时候, 字段4 的最小值 
条件2=字段1,字段2,字段3 相同的时候, 字段4 的最大值 
条件3是字段5=xxx1 
条件4是字段6=xxx2 通过查询我想要得到的效果是 
字段1   字段2   字段3   字段4    字段5  字段6
  A      B      C      001      1     11
  A      B      C      003      3     33
  A      B      D      004      4     44
  A      B      D      006      6     66

解决方案 »

  1.   

    似乎只有用union 实现 ..
      

  2.   


    SELECT DISTINCT 字段1, 字段2, 字段3, A
      FROM (SELECT 字段1, 字段2, 字段3, MIN(字段4) A,MIN(字段5) b,MIN(字段6) c
              FROM TABLEA 
             GROUP BY 字段1, 字段2, 字段3
            UNION ALL
            SELECT 字段1, 字段2, 字段3, MAX(字段4),MAX(字段5) b,MAX(字段6) c
              FROM TABLEA 
             GROUP BY 字段1, 字段2, 字段3);
      

  3.   

    字段1  字段2  字段3  字段4    字段5  字段6 
      A      B      C      001      1    11 
      A      B      C      002      2    22 
      A      B      C      003      3    33 
      A      B      D      004      4    44 
      A      B      D      005      5    55 
      A      B      D      006      6    66 select 字段1,字段2,字段3....from 表 
    where (条件1 or 条件2) and 条件3 and 条件4 
    group by 字段1,字段2,字段3
    order by 字段1,字段2,字段3,字段4条件1=字段1,字段2,字段3 相同的时候, 字段4 的最小值 
    条件2=字段1,字段2,字段3 相同的时候, 字段4 的最大值 
    条件3是字段5=xxx1 
    条件4是字段6=xxx2 通过查询我想要得到的效果是 
    字段1  字段2  字段3  字段4    字段5  字段6 
      A      B      C      001      1    11 
      A      B      C      003      3    33 
      A      B      D      004      4    44 
      A      B      D      006      6    66 请问要怎么做
      

  4.   

    SELECT DISTINCT 字段1, 字段2, 字段3, A
      FROM (SELECT 字段1, 字段2, 字段3, MIN(字段4) A,MIN(字段5) b,MIN(字段6) c
              FROM TABLEA 
             GROUP BY 字段1, 字段2, 字段3
            UNION ALL
            SELECT 字段1, 字段2, 字段3, MAX(字段4),MAX(字段5) b,MAX(字段6) c
              FROM TABLEA 
             GROUP BY 字段1, 字段2, 字段3);我想把这个表里的所有字段都要列出来 
      

  5.   

    union不是有人回了你的问题了吗?版主,有人砸场子呀!  :)
      

  6.   

    你那个字段5=xxxx和字段6=xxxx是并列的还是求和条件1和2的交集。我这是求交集的脚本:
    select *
      from (select *
              from table1
             where 字段4 in (select min(字段4)
                               from table1 t
                              group by t.字段1, t.字段2, t.字段3)
            union all
            select *
              from table1
             where 字段4 in (select max(字段4)
                               from table1 t
                              group by t.字段1, t.字段2, t.字段3))
     where 字段5 = 3
       and 字段6 = 33