请教一条SQL语句的写法

janlay 2003-08-20 10:42:04
在一次检索A表的全部字段时,有一个列f,我想在检查它是否存在于B表的某列f中,并将这个结果作为检索结果的新列,并且要依此排序。这样写行不行?

select a.*,a.f in(select f from b) as result from a order by result
...全文
19 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-08-20
  • 打赏
  • 举报
回复
select a.*,aa=case when exists(select 1 from b where f=a.f) then '存在' else '不存在' from a order by aa
chao778899 2003-08-20
  • 打赏
  • 举报
回复
select a.*,case when f in (select f from b) then '存在' else '不存在' end result from a order by result
行吗?
CrazyFor 2003-08-20
  • 打赏
  • 举报
回复
select a.*,b.f from a left join b on a.f=b.f order by b.f
CrazyFor 2003-08-20
  • 打赏
  • 举报
回复
select a.*,b.f from a left join b on a.f=b.f order by b.f
pengdali 2003-08-20
  • 打赏
  • 举报
回复
select a.*,case when f in (select f from b) then '存在' else '不存在' end result from a order by case when f in (select f from b) then '存在' else '不存在' end

34,575

社区成员

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

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