有如下表 课程(课程号,教室编号,课程名称,周次,星期,节次,课程学时,院系名称,班级,人数)
vb中如何实现查询 某周次 某星期 某节次不再使用的教室???

解决方案 »

  1.   

    select classroomID from tbl where classroomID not in(select classroomID from tbl where weekNo=8 and week=5 and classNo=0)理论上你应该还有一个表格,就是所有教室的表格。比如tblClassroom里面有ID, buildingNo,FloorNo..
    然后用两个表来join查询select tblClassroom.classroomID from tblClassroom where tblClassroom.classroomID not in(select classroomID from tbl where weekNo=8 and week=5 and classNo=0)
      

  2.   

    楼上:
    那样的话查询的是在使用的教室,我要的是不在使用的教室。是用where not  existes()
    教室借用表(教室编号,使用人编号,使用日期,借用时间段,工作日,用途)
    我是这样写的
    Private Sub Command1_Click()
    Adodc2.RecordSource = "SELECT 教室借用表.* FROM 教室借用表 where not exists(select * from 课程 where 课程.教室编号=教室借用表.教室编号 周次='" & Combo1.Text & "'and  星期='" & Combo2.Text & "' and 节次='" & Combo3.Text & "')"
    Set DataGrid3.DataSource = Adodc2
    Adodc1.Refresh
    End Sub
    但是无法查询
      

  3.   

    同意楼上select * from 教室表 where 教室编号 not in(select 教室编号 from 课程 where 周次=某周次  and 星期=某星期  and 节次=某节次)
      

  4.   

    楼主试一下下面的语句:"select * from 课程 where  周次='" & Combo1.Text & "' and  星期='" & Combo2.Text & "'   and 节次='" & Combo3.Text & "' and   教室编号 not in (select 教室编号 from 教室借用表)"
      

  5.   

    按你说的先选出某周次  某星期的课程教室编号都选出来就是:
    select 教室编号 from 课程 where 周次=某周次  and 星期=某星期再判定某节次没课的教室
    '先取在该区间的教室
    select 教室编号 from 课程 where 周次=某周次  and 星期=某星期  and 节次=某节次 最后用NOt In 即去掉了在区间的教室,剩下的应该就是你要的了吧:select 教室编号 from 课程 where 周次=某周次  and 星期=某星期 and 教室编号 not in(select 教室编号 from 课程 where 周次=某周次  and 星期=某星期  and 节次=某节次)