当前位置: 代码迷 >> Sql Server >> 关于统计有关问题
  详细解决方案

关于统计有关问题

热度:169   发布时间:2016-04-27 19:27:07.0
关于统计问题
有两个表  
 A  
  会议室名 会议地点 会议时间
  奥运会 上海 2008
  农博会 北京 2008
 B
  会议室名 用户名  
  奥运会 中国
  奥运会 美国
  奥运会 德国
  农博会 中国

 现在要查询 用户数 大于3的 会议室的信息(根据B表判断用户数)
  即显示如下
  会议室名 会议地点 会议时间
  奥运会 上海 2008

请问查询语句如何写,谢谢
   
 
  





------解决方案--------------------
A
会议室名 会议地点 会议时间 
奥运会 上海 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 会议室名 FROM B group by 会议室名 having count(1)>2)
------解决方案--------------------
SQL code
create table #a(会议室名 varchar(10), 会议地点  varchar(10),  会议时间 varchar(10))create table #b(会议室名 varchar(10), 用户名  varchar(10))insert into #a select '奥运会','上海','2008' union all select '农博会','北京','2008'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*/
  相关解决方案