解决方案 »
- 求插入数据(insert语句)的解决方法
- sql查询后的结果集 再增加一列
- 菜鸟问个问题 关于SQL Server 2005
- 厚颜求个简单sql...
- sql怎么实现查询结果中再分类排序啊,求大神们帮助,急啊。。。。。
- 索引 结构 的疑问 ?
- 关于自动去掉varchar char 中前边的0 的问题。
- 请问用restore语句恢复数据库,怎样指定数据库路径?(即*.mdf,*.ldf的路径)
- SQL SERVER 中的smalldatetime和datetime有什么区别?
- VFP中使用外部控件的注册问题
- 存储过程的基础问题,大家多来帮我看看
- 【请教】能否多个客户端直接连接,存储远程SQL数据库
SELECT Gp_id FROM b WHERE X IN (select X from A) GROUP BY Gp_id having count(1) =2
create table A(x int)insert into A
select 1 union all
select 2create table B(Gp_id int,x int)insert into B
select 1,1 union all
select 1,2 union all
select 2,2 union all
select 2,3 union all
select 3,1 union all
select 3,3 union all
select 4,1 union all
select 4,2
select Gp_id
from B
inner join A on B.x=A.x
group by Gp_id
having count(1)=(select count(1) from A)/*
Gp_id
-----------
1
4(2 row(s) affected)
*/
select Gp_id,x
from B
where Gp_id in
(select Gp_id
from B
inner join A on B.x=A.x
group by Gp_id
having count(1)=(select count(1) from A)
)/*
Gp_id x
----------- -----------
1 1
1 2
4 1
4 2(4 row(s) affected)
*/
select Gp_id from b inner join a on a.x = b.x group by Gp_id having count(1)=(select count(1) from a)
select * from b
where GP_ID IN
(select Gp_id from b inner join a on a.x = b.x
group by Gp_id having count(1)=(select count(1) from a))