select 车次 from 一个表 where 站名 in ('a','b') group by 车次 having count(distinct 站名)=2
解决方案 »
- sql server 2000和 sql server 2005 服务器端能否同时安装?
- 如何用select语句取数据的第20条到第30条记录
- 这个sql语句什么问题?
- 这样的数据有办法更新么?
- 多表查询问题
- 为什么日期格式变了,提示“从 char 数据类型到 datetime 数据类型的转换导致 datetime 值越界”
- 关于sql server7.0的空间占用问题?
- 工资计算中的所得税处理时,我想写个更新的触发器,但影响它的列太多,怎么写?
- 无法为更新行集定位:一些值可能己在最后读取后改变???????
- 纯小白求公式
- 请问, 我把远程的sql server 服务器端改了以后。 在本地怎么连接?
- 关于datename函数(在线等待)
from table a
where exists(select top 1 1 from table where 车次=a.车次 and 站名='a')
and 车次 ='b'
from 表 a inner join 表 b on a.车次=b.车次 and (a.站名='a' and b.站名='b' or (a.站名='b' and b.站名='a' ))
where 车次 in (select 车次 from yourTable where 站名=a )
and 车次 in (select 车次 from yourTable where 站名=b )
from table a
where exists(select top 1 1 from table where 车次=a.车次 and 站名='a')
and 站名 ='b'
select 车次 from 一个表 where 站名 in ('a','b') group by 车次
group by 车次
是啊,我刚试过.
假如a 和 b 之间还有其他车站, select 车次 from 车次表 where 站名 in ('a','b') group by 车次
就不正确了!
这样的话经过a.b任一站点的车次均显示.不合楼主要求select 车次 from tablename
where 站点 in('a','b')
group by 车次
having count(车次)=2