有两个表
A
会议室名 会议地点 会议时间
奥运会 上海 2008
农博会 北京 2008
B
会议室名 用户名
奥运会 中国
奥运会 美国
奥运会 德国
农博会 中国 现在要查询 用户数 大于3的 会议室的信息(根据B表判断用户数)
即显示如下
会议室名 会议地点 会议时间
奥运会 上海 2008请问查询语句如何写,谢谢
A
会议室名 会议地点 会议时间
奥运会 上海 2008
农博会 北京 2008
B
会议室名 用户名
奥运会 中国
奥运会 美国
奥运会 德国
农博会 中国 现在要查询 用户数 大于3的 会议室的信息(根据B表判断用户数)
即显示如下
会议室名 会议地点 会议时间
奥运会 上海 2008请问查询语句如何写,谢谢
会议室名 会议地点 会议时间
奥运会 上海 2008
农博会 北京 2008
B
会议室名 用户名
奥运会 中国
奥运会 美国
奥运会 德国
农博会 中国 现在要查询 用户数 大于3的 会议室的信息(根据B表判断用户数)
即显示如下
会议室名 会议地点 会议时间
奥运会 上海 2008 select 会议室名,会议地点,会议时间 from A WHERE 会议室名 IN (SELECT 会议室名 FROM B group by 会议室名 havint count(1)>2)
select * from A where [会议室名] in (select B.[会议室名] from B
group by B.[会议室名] having Count(*)>2)
insert into #b select '奥运会','中国' union all select '奥运会','美国'union all select '奥运会','德国'union all select '农博会','中国'
select * from #a where 会议室名 in
(select 会议室名 from #b group by 会议室名 having count(1)>2)/*
会议室名 会议地点 会议时间
---------- ---------- ----------
奥运会 上海 2008
*/
create table A
(
会议室名 nvarchar(8) not null,
会议地点 nvarchar(2) not null,
会议时间 int
)insert
into A
values('奥运会','上海','2008');insert
into A
values('农博会','北京','2008');select *
from A
------------------------------------------------
create table B
(
会议室名 nvarchar(8) not null,
用户名 nvarchar(5) not null
)insert
into B
values('奥运会','中国');insert
into B
values('奥运会','美国');insert
into B
values('奥运会','德国');insert
into B
values('农博会','中国');select *
from B
------------------------------------------------
select 会议室名,会议地点,会议时间
from A
where 会议室名 in
(
select 会议室名
from B
group by 会议室名 having count(*)>2
)
(select 会议室名 from B group by 会议室名 having count(*)>2)
where [会议室名] in
(select B.[会议室名] from B
group by B.[会议室名] having Count(*)>2)
select a.会议室名 ,a.会议地点 , a.会议时间
from a , b
where a.会议室名 = b.会议室名
and a.会议地点 = b.会议地点
group by a.会议室名 ,a.会议地点 , a.会议时间
having count(1) > 2