日期:2014-05-18 浏览次数:20623 次
---->>TravyLee生成测试数据 if OBJECT_ID('Course')is not null drop table Course go create table Course( CouID int, CouType varchar(10) ) go insert Course select 1,'Java' union all select 2,'SQL Server' union all select 3,'HTML5' if OBJECT_ID('CouBooked')is not null drop table CouBooked go create table CouBooked( BookedID int, CouID int, CouType varchar(10)--不明白为什么还要一个课程类型 ) go insert CouBooked select 1,1,'test1' union all select 2,1,'test2' union all select 3,3,'test3' union all select 4,2,'test4' union all select 5,1,'test5' union all select 6,1,'test6' union all select 7,2,'test7' union all select 8,2,'test8' union all select 9,2,'test9' union all select 10,1,'test10' union all select 11,3,'test11' union all select 12,1,'test12' go select CouID,CouType from Course where CouID in( select CouID from( select CouID,COUNT(CouID) as Times from CouBooked group by CouID having COUNT(CouID)>=4 )t ) /* CouID CouType -------------------------- 1 Java 2 SQL Server */