sql搜索 如何过滤掉重复的信息?

visp 2007-01-30 04:09:04
我最近在做一个招聘的网站,里面的一个企业发布的职位表job_info
结构为
pid 自动编号
s_name 工作名称
s_mem 企业名称


如:
1 程序员 A单位
2 清洁工 A单位
3 程序员 B单位
4 经理 A单位
5 财务 C单位
6 工程员 A单位

我想搜索出最后发布信息的10个单位。
如上面的数据我想搜索出的结果是

A单位
C单位
B单位

请问如何过滤掉重复的信息,这个sql语句应该怎么写?
...全文
298 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
marco08 2007-01-30
  • 打赏
  • 举报
回复
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)
中国风 2007-01-30
  • 打赏
  • 举报
回复
select * from table1 a
where (select count(*)from table1 where pid>a.pid)<10--把id改为pid
中国风 2007-01-30
  • 打赏
  • 举报
回复
select * from table1 a
where (select count(*)from table1 where id>a.id)<10
中国风 2007-01-30
  • 打赏
  • 举报
回复
select * from table1 a
where (select count(*) from table1 where pid<a.pid)!>10

34,594

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧