读书人

不会表达看帖子内容吧!多谢

发布时间: 2013-06-19 10:26:41 作者: rapoo

不会表达,看帖子内容吧!~~在线等,谢谢!
例:表1
lsh zzsl je
0523 17 10
0523 13 5
0523 0 40
0523 17 21
1526 13 9
... ...

问:我怎么样select 只有指定zzsl的?
比如说我只想select 表内一笔lsh只有13的
select * from 表1 where zzsl=13
但这样上面0523也会显示,我只要1526这样完全符合要求的。
[解决办法]

select * from [tb] a
where not exists(select 1 from lsh=a.lsh and zzsl<>a.zzsl) and zzsl=13

[解决办法]
select * from t2 a
where not exists(select 1 from t2 where lsh=a.lsh and zzsl<>a.zzsl)
[解决办法]
引用:
Quote: 引用:

lz的意思我不是很明白
但是如果你只返回最新的一个的话,可以是这样子的
select top 1 * from 表1 where zzsl=13
order by lsh

不是,我是要只显示开过票的lsh,而且这个流水号只开过13的zzsl.
像0523这样的开过0,17,13的不符合我的要求。
而像1526这样lsh,只开过13的才符合我的要求。


select * from [tb] a
where not exists(select 1 from [tb] where lsh=a.lsh and zzsl<>a.zzsl) and zzsl=13

读书人网 >SQL Server

热点推荐