问一个查询语句 有点难度(在线等)

ou630j 2009-02-25 05:17:28
假设表数据
id name addr cltcode state addrto
1 利斯 lishi@123.com A001 1 wang@123.com
2 万户 wang@123.com a002 1 lishi@123.com
3 成行 cheng@123.com A005 1 cheng@123.com
4 红色 hongse@123.com 6002 1 cheng@123.com
5 海欧 hai@123.com 123 3 cheng@123.com
6 女生 nv@123.com 524 1 cheng@123.com
7 互补 hu@123.com 666 2 cheng@123.com


现在我想得到的结果是
state=1 这个必须的
1 利斯 lishi@123.com A001 1 wang@123.com
2 万户 wang@123.com a002 1 lishi@123.com
3 成行 cheng@123.com A005 1 cheng@123.com
4 红色 hongse@123.com 6002 1 cheng@123.com
6 女生 nv@123.com 524 1 cheng@123.com

然后 addr或者 addrto=cheng@123.com
3 成行 cheng@123.com A005 1 cheng@123.com
4 红色 hongse@123.com 6002 1 cheng@123.com
6 女生 nv@123.com 524 1 cheng@123.com

最后得到 cltcode= A005 或者cltcode=6002
3 成行 cheng@123.com A005 1 cheng@123.com
4 红色 hongse@123.com 6002 1 cheng@123.com


我想一条语句得到这结果

3 成行 cheng@123.com A005 1 cheng@123.com
4 红色 hongse@123.com 6002 1 cheng@123.com

...全文
76 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
wsxcdx 2009-02-25
  • 打赏
  • 举报
回复
select * from 表 where state=1 and 'cheng@123.com' in(addr,addrto) and cltcode in('A005','6002')
dobear_0922 2009-02-25
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ou630j 的回复:]
1
select * from tb
where state=1 and (addr='cheng@123.com' or addrto='cheng@123.com')
and (cltcode= 'A005' or cltcode='6002' )
2
select * from 表 where state=1 and 'cheng@123.com' in(addr,addrto) and cltcode in('A005','6002')

请问那种速度快点啊
[/Quote]

1
ou630j 2009-02-25
  • 打赏
  • 举报
回复
1
select * from tb
where state=1 and (addr='cheng@123.com' or addrto='cheng@123.com')
and (cltcode= 'A005' or cltcode='6002' )
2
select * from 表 where state=1 and 'cheng@123.com' in(addr,addrto) and cltcode in('A005','6002')

请问那种速度快点啊
pt1314917 2009-02-25
  • 打赏
  • 举报
回复

select * from 表 where state=1 and (addr='cheng@123.com' or addrto='cheng@123.com') and cltcode in('A005','6002')

nothinghan 2009-02-25
  • 打赏
  • 举报
回复
设TABLE 名为A
SELECT * FROM A WHERE state=1 and (addrto='cheng@123.com' or addr='cheng@123.com') and (cltcode='A005' or cltcode='6002')
dobear_0922 2009-02-25
  • 打赏
  • 举报
回复
select * from tb
where state=1 and (addr='cheng@123.com' or addrto='cheng@123.com')
and (cltcode= 'A005' or cltcode='6002' )
flairsky 2009-02-25
  • 打赏
  • 举报
回复
where state = 1 and (add = cheng@123.com or addrto=cheng@123.com ) and (cltcode= A005 或者cltcode=6002)
子陌红尘 2009-02-25
  • 打赏
  • 举报
回复

select * from 表 where state=1 and 'cheng@123.com' in(addr,addrto) and cltcode in('A005','6002')

22,206

社区成员

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

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