求助:高手进,需要在多个表操作中取出一个字段的重复值

free200282 2008-03-27 11:51:16
select f.workno,f.name,f.deptid,c.*from fixfield f ,contract c where convert(char,c.EndTime,111) like '%2008/02%' and c.employeeid=f.workno and f.emptype!='退休' and f.emptype!='死亡' and f.emptype!='调出'order by f.workno
需要把工号,去掉工号f.workno重复的项,求高手帮忙!!
...全文
40 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
dawugui 2008-03-27
  • 打赏
  • 举报
回复
select f.workno,f.name,f.deptid,c.*from fixfield f ,contract c where convert(char,c.EndTime,111) like '%2008/02%' and c.employeeid=f.workno and f.emptype!='退休' and f.emptype!='死亡' and f.emptype!='调出'order by f.workno
需要把工号,去掉工号f.workno重复的项,求高手帮忙!!
----------------------------------------------
workno重复的情况下?假设name不重复(或某个字段)

select m.* from
(
select f.workno,f.name,f.deptid,c.*from fixfield f ,contract c where convert(char,c.EndTime,111) like '%2008/02%' and c.employeeid=f.workno and f.emptype!='退休' and f.emptype!='死亡' and f.emptype!='调出'order by f.workno
) m where name = (select max(name) from
(
select f.workno,f.name,f.deptid,c.*from fixfield f ,contract c where convert(char,c.EndTime,111) like '%2008/02%' and c.employeeid=f.workno and f.emptype!='退休' and f.emptype!='死亡' and f.emptype!='调出'order by f.workno
) n where workno = m.workno
)
viva369 2008-03-27
  • 打赏
  • 举报
回复
+ distinct ?

22,298

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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