同一表中,查询时怎么将字段区分

Maxdell 2008-05-14 12:49:54
表t1
----------
id name
----------------
1 ssss
2 dddd
....


select name as n1,name as n2 from t1 where n1=(select ....) ,n2=(select ...)

怎样将name字段用参数表示呢?
...全文
99 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
Limpire 2008-05-14
  • 打赏
  • 举报
回复
不明需求,看句型是不可能实现的。
-狙击手- 2008-05-14
  • 打赏
  • 举报
回复
select id,case when name ... then name end as n1,
......
from t1
Limpire 2008-05-14
  • 打赏
  • 举报
回复
select (name as n1 from t1 where ...), (name as n2 from t1 where ...)
dawugui 2008-05-14
  • 打赏
  • 举报
回复
select name as n1,name as n2 from t1 where n1 in (select ....) and n2 in (select ...)
中国风 2008-05-14
  • 打赏
  • 举报
回复
select * from T1  a where exists(select 1 from t1 where ID=a.ID and Name='?') and exists
(select 1 from t1 where ID=a.ID and Name='??')--应有一个条件ID与外表连

----------------
if exists(select 1 from T1 where Name='?') and exists(select 1 from T1 where Name='??')
select * from T1
中国风 2008-05-14
  • 打赏
  • 举报
回复
或:
select * from T1 a where exists(select 1 from t1 where Name='?') and exists
(select 1 from t1 where Name='??')
中国风 2008-05-14
  • 打赏
  • 举报
回复
可以,别名x\y没有连接条件为布尔表达式?
Maxdell 2008-05-14
  • 打赏
  • 举报
回复
select x.name,y.name from t1 as x,t1 as y where x.name ... and y.name ...

我想把 x.name ,y.name 当作后面 where 操作的参数。
可能是我方法不对,呵呵,没有这种把别名当作字段来操作的吗?

34,593

社区成员

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

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