我最近在做一个招聘的网站,里面的一个企业发布的职位表job_info
结构为
pid 自动编号
s_name 工作名称
s_mem  企业名称
如:
1 程序员 A单位
2 清洁工 A单位
3 程序员 B单位
4 经理   A单位
5 财务   C单位
6 工程员 A单位我想搜索出最后发布信息的10个单位。
如上面的数据我想搜索出的结果是A单位
C单位
B单位请问如何过滤掉重复的信息,这个sql语句应该怎么写?

解决方案 »

  1.   

    select * from table1 a
    where (select count(*) from table1 where pid<a.pid)!>10
      

  2.   

    select * from table1 a
    where (select count(*)from table1 where id>a.id)<10
      

  3.   

    select * from table1 a
    where (select count(*)from table1 where pid>a.pid)<10--把id改为pid
      

  4.   

    create table T(pid int, s_name varchar(10), s_mem varchar(10))
    insert T select   1, '程序员', 'A单位'
    union all select 2, '清洁工', 'A单位'
    union all select 3, '程序员', 'B单位'
    union all select 4, '经理',   'A单位'
    union all select 5, '财务',   'C单位'
    union all select 6, '工程员', 'A单位'set rowcount 10
    select * from T as tmp
    where not exists(select 1 from T where s_mem=tmp.s_mem and pid>tmp.pid)
    order by pid desc
    set rowcount 0--result
    pid         s_name     s_mem      
    ----------- ---------- ---------- 
    6           工程员        A单位
    5           财务         C单位
    3           程序员        B单位(3 row(s) affected)