一个比较复杂的搜索,请给出SQL语句,谢谢了!!

哈哈哈哈 2003-01-20 12:42:15
select * from table where ndate='2003' or ndate='2000'

但是,如果2003和2000同时有某个字段时,我只想让它列出ndate=2000的那条信息该怎么办,SQL语句改怎么写???

谢谢!
...全文
32 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yelook 2003-01-20
  • 打赏
  • 举报
回复
select a.* from (select * from table where ndate='2003' or ndate='2000') a inner join (select min(ndate),field from table where ndate='2003' or ndate='2000' group by field) b on a.field=b.field and a.ndate=b.ndate
yelook 2003-01-20
  • 打赏
  • 举报
回复
select a.* from (select * from table where ndate='2003' or ndate='2000') a inner join (select min(ndate),field from table where ndate='2003' or ndate='2000' group by field) b on a.filed=b.filed
CrazyFor 2003-01-20
  • 打赏
  • 举报
回复
select * from table where ndate='2000'
是这个意思吗?
weixxxp 2003-01-20
  • 打赏
  • 举报
回复
select * from table where (ndate='2003' and field not in (select distinct a.field from table a where ndate='2000')) or ndate='2000'

34,576

社区成员

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

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