在视图中建个源表中没有,但根据源表计算出来的字段

aloneone 2003-08-22 03:10:41
table1
zlbm char(10)
......
//-------------------------------

table2:
zlbm char(10)
......
//-------------------------------

View1:从table1中取若干字段,另加一逻辑字段YN,当table1.zlbm在table2中出现时,YN的值为T,否则为F。
...全文
62 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
aloneone 2003-09-15
  • 打赏
  • 举报
回复
没人回答?我结贴算了。
aloneone 2003-08-24
  • 打赏
  • 举报
回复
三种方法我都试成功了,再多问一个问题,哪种方法的效率高些呢?
dafu71 2003-08-22
  • 打赏
  • 举报
回复
select table1.*, 'T' as YN from table1 where exists (select 1 from table2 where table1.zlbm=table2.zlbm)
union
select table1.*, 'F' as YN from table1 where not exists (select 1 from table2 where table1.zlbm=table2.zlbm)

caiyunxia 2003-08-22
  • 打赏
  • 举报
回复
select * ,case when (select top 1 zlbm from table2 where zlbm=table1.zlbm) is not null then 't' else 'f' end as yn
from table1
yujohny 2003-08-22
  • 打赏
  • 举报
回复
同意caiyunxia(monkey)
caiyunxia 2003-08-22
  • 打赏
  • 举报
回复
select table1.*,(case when table2.zlbm is null then 'f' else 't' end ) as yn
from table1 left join table2 on table1.zlbm=table2.zlbm

22,209

社区成员

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

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