select * from A group by 编号 where having MIN(学历)
语句是错的,我是想查询到这样的结果

解决方案 »

  1.   

    select T1.*
    from tab T1 inner join (select 编号,Min(学历) from tab where 上学形式='脱产' group by 编号) T2 on T1.编号=T2.编号 and T1.学历=T2.学历这个语句也不行,提示SQL语句非正常结束 
      

  2.   

    select * from a where 编号 in (select 编号 from A group by 编号 where having MIN(学历))
      

  3.   

    select a.* from a,(select 编号 from A group by 编号 where having MIN(学历) where 编号) b where a.编号=b.编号
      

  4.   

    select a.* from a,(select 编号 from A group by 编号 where having MIN(学历) where 编号) b where a.编号=b.编号
    a,是什么意思?
    having min(学历)执行不了
    有谁能帮忙?
      

  5.   

    select a.* from a where 上学形式=脱产 and 学历=(select min(学历) from a b where b.编号=a.编号)
    没有把握,你试试看吧。
      

  6.   

    按照,我的理解,你这个表A里,编号和学历是主关键字,而且都是
    字符型。
    所以可以按以下方法写:select * from a where 编号+';'+学历 in 
    (select 编号+';'+min(学历) from a where 上学形式='脱产' group by 编号)相信我,没错的。
      

  7.   

    SQL> select * from b;身份号     毕业院校   培训形式    文化程度 姓名
    ---------- ---------- ---------- --------- ----------
    2          南京大学   脱产               4 李三
    2          人民大学   脱产               3 李三
    4          北京大学   脱产               3 吴仁
    4          清华大学   在职               2 吴仁SQL> select b.* from b,(select 身份号,min(文化程度) 文化程度 from b where 培训形式='脱产' 
      2  group by 身份号) b1 where b1.身份号=b.身份号 and b1.文化程度=b.文化程度;身份号     毕业院校   培训形式    文化程度 姓名
    ---------- ---------- ---------- --------- ----------
    2          人民大学   脱产               3 李三
    4          北京大学   脱产               3 吴仁
      

  8.   

    select b.* from b,
    逗号是什么意思?
      

  9.   

    假定table 名为:example。
    SQL语句如下:
    SELECT a.* 
      FROM (SELECT 编号,MIN(学历) AS 学历1 
     FROM example 
    GROUP BY 编号
            ) b,example a 
     WHERE b.编号 = a.编号 
       AND b.学历1 = a.学历 
       AND a.上学形式 = '脱产'其实上面有位仁兄(junglerover(灌木丛))的方式最好。
      

  10.   

    to junglerover(灌木丛) 只能是数字型才行把它的句法改成以下可用:select * from a where 编号||学历 in 
    (select 编号||min(学历) from a where 上学形式='脱产' group by 编号)
      

  11.   

    现在可以查出每个人的最高学历的记录了
    但现在的问题是有人上了两次大学,学历都是本科
    查询结果中这个人的两次记录都出来了
    我的想法是:每个人的记录只要一条,最高学历的,培训形式是脱产的
    另外:
    select 编号||min(学历) from a where 上学形式='脱产' group by 编号
    select 编号,min(学历) 学历 from a where 上学形式='脱产'  group by 编号
    这两个语句有什么区别?
      

  12.   

    现在可以查出每个人的最高学历的记录了
    但现在的问题是有人上了两次大学,学历都是本科
    查询结果中这个人的两次记录都出来了
    我的想法是:每个人的记录只要一条,最高学历的,培训形式是脱产的,时间是最近上的学
    例如:select * from a where 编号||学历 in 
    (select 编号||min(学历) from a where 上学形式='脱产' group by 编号)
    得到:
    100  李三  南京大学  脱产  1998.09.01  本科
    100  李三  天津大学  脱产  1992.09.01  本科
    ....
    我现在只需要得到
    100  李三  南京大学  脱产  1998.09.01  本科
    记录就可以了
      

  13.   

    select * from (select * from a where 编号||学历 in 
    (select 编号||min(学历) from a where 上学形式='脱产' group by 编号)) b where rowid=(select min(rowid) from b group by 编号)
      

  14.   

    beckhambobo(beckham)
    select * from (select * from a where 编号||学历 in 
    (select 编号||min(学历) from a where 上学形式='脱产' group by 编号)) b where rowid=(select min(rowid) from b group by 编号)
    不行啊
    -----------------------------------
    where rowid=(select min(rowid) from b group by 编号)
    第3行有错:
    ORA-00942:表或试图不存在select * from a where 编号||学历 in 
    (select 编号||min(学历) from a where 上学形式='脱产' group by 编号)
    执行正常
      

  15.   

    select a.*
    from a,(select 编号,min(学历) as 学历 from a where 上学形式='脱产' group by 编号) b,   (select 编号,学历,max(入学时间) as 入学时间 from a where 上学形式='脱产' group by 编号,学历 ) c
    where a.编号 = b.编号
      and a.学历 = b.学历
      and a.编号 = c.编号
      and a.学历 = c.学历
      and a.入学时间 = c.入学时间
      

  16.   

    select * from (select * from a where 编号||学历 in 
    (select 编号||min(学历) from a where 上学形式='脱产' group by 编号)) b where b.rowid=(select min(b.rowid) from b group by 编号)
      

  17.   

    to 楼上beckhambobo(beckham):我试了一下不可以的,具体情况如下
    1. 第3行 b.rowid=(select min(b.rowid) from b group by 编号)中,后面返回的是个集合,应该是 b.rowid in (……)
    2. 整个SQL的最后那个from b 中的表b 好像不能这样用的,因为表b是一个虚表
    3. 楼主的需求是最后一次时间的记录,所以用min(rowid)应该是不可以的吧希望楼住尽快试一下,告诉我们结果,也希望高手来指教指教,我们新手好共同学习。
      

  18.   

    select * from a where 编号||学历||入学时间 in 
    (select 编号||min(学历)||min(入学时间) from a where 上学形式='脱产' group by 编号)
      

  19.   

    To: cyberflying(雁南飞) 
    b表确实是个虚表,我试了是错误的
    另外你写的句子执行是正常的,查询结果目前看是正确的,不过等我的记录全输入进去后,再核对一下To: beckhambobo(beckham) 
    select * from a where 编号||学历||入学时间 in 
    (select 编号||min(学历)||max(入学时间) from a where 上学形式='脱产' group by 编号)
    这个语句很是精简,应该很好用,我回头试试
      

  20.   

    select 编号||min(学历)||min(入学时间) from a where 上学形式='脱产' group by 编号select 编号||min(学历)||max(入学时间) from a where 上学形式='脱产' group by 编号这样是不对的,因为取到的最小学历或最大时间只是对于同一个组(group by 编号group by 编号)中来说最小和最大的,有种情况是最小和最大对应的不是同一条记录。
      

  21.   

    to: spear_nj(留个微笑给我)
    我写的那个应该符合你的要求,但是我觉得还应该有更好的方法。帮你UP一下吧
      

  22.   

    select * from a ,(select min(入学时间) 入学时间 from a where 编号||学历 in (select 编号||min(学历) from a where 上学形式='脱产' group by 编号) group by 编号)b where a.入学时间=b.入学时间;可能速度上会减慢,楼主自已测试下吧
      

  23.   

    sorry,大家共同进步吧,select * from a ,(select 编号,min(入学时间) as 入学时间 from a where 编号||学历 in (select 编号||min(学历) from a where 上学形式='脱产' group by 编号) group by 编号)b where a.入学时间=b.入学时间 and a.编号 = b.编号;如果语句变得复杂,那楼主的数据结构变得不严谨了,为何不为每条记录多加一个唯一标识符呢,那会使问题变得简单化!
    good luck