两个数据表 连接查询 以及与Gridview的显示问题
我有两个表,一个是 课程信息表 C_ID, C_Style (课程编号,课程类型)
,另一个是 定课表,B_ID,C_ID,C_Style(定课id,课程编号,课程类型)
我用gridview绑定课程信息,用textbox对C_Style课程类型进行搜索。
我现在要实现的是gridview 搜索显示出来的信息为 在定课表中C_ID出现的次数小于4的 课程信息表中的相应信息。
请问各大神怎么实现?
[解决办法]
---->>TravyLee生成测试数据if OBJECT_ID('Course')is not nulldrop table Coursegocreate table Course(CouID int,CouType varchar(10))goinsert Courseselect 1,'Java' union allselect 2,'SQL Server' union allselect 3,'HTML5'if OBJECT_ID('CouBooked')is not nulldrop table CouBookedgocreate table CouBooked(BookedID int,CouID int,CouType varchar(10)--不明白为什么还要一个课程类型)goinsert CouBookedselect 1,1,'test1' union allselect 2,1,'test2' union allselect 3,3,'test3' union allselect 4,2,'test4' union allselect 5,1,'test5' union allselect 6,1,'test6' union allselect 7,2,'test7' union allselect 8,2,'test8' union allselect 9,2,'test9' union allselect 10,1,'test10' union allselect 11,3,'test11' union allselect 12,1,'test12'goselect CouID,CouTypefrom Coursewhere CouID in(select CouIDfrom(select CouID,COUNT(CouID) as Times from CouBooked group by CouIDhaving COUNT(CouID)>=4 )t )/*CouID CouType--------------------------1 Java2 SQL Server*/