1

我有一个选择语句::

    SELECT [Course ID], [Course name] 
FROM Courses 
WHERE [Course ID] NOT IN 
(SELECT [Course ID] from student_courses sc
  INNER JOIN Courses c ON sc.[course ID] = c.[course ID] 
  WHERE [student ID] = 1
  AND (c.[course start time] not BETWEEN Courses.[course start time] AND Courses.[course end time]
  OR c.[course end time] not BETWEEN Courses.[course start time] AND Courses.[course end time]))

它不断给出以下错误::

数据类型日期和时间在小于或等于运算符中不兼容....

不明确的列名称“课程 ID”

如何修复这些错误并实际比较数据类型的列time(7)

4

1 回答 1

2

您需要将日期转换为时间,即

CAST(<YOUR DATE> AS time(7))

并且要摆脱模棱两可的列,您需要在表中添加一个别名,因为 student_courses 和 course 都有courseId

如果不运行它,问题看起来像它在子查询中

select **c.[Course ID]** from student_courses sc inner join Courses c on sc.[Course ID] = c.[Course ID]
    where [student ID]=@val1
    AND ((c.[Course start date] between Courses.[Course start date] and Courses.[Course end time])
    or (c.[Course end time] between Courses.[Course start time] and Courses.[Course end time]) 
    )
于 2012-12-12T14:37:56.963 回答