select
sc.locationid, --here to get a result
(
if month(date()) between 8 and 12 then @semTerm = 'S1'
else @semTerm = 'S2'
end if
)as @semTerm
from student_class sc
where @semTerm = sc.semester
;
在 db2 学生管理系统中。只读访问。期望的结果是如果 1 月到 6 月,S2,否则如果 8 月到 12 月,S1。尝试根据当前日期戳设置变量,其中月份被隔离,然后分配给变量,然后与 student_class 表中的列进行比较。
也尝试过案例陈述,但没有运气。无法在选择语句上方无错误地声明 @semTerm。还查看了where子句解决方案。我在左外野吗?看起来很简单,但在语法上很挣扎。较大语句的一部分,其中 locationID 作为 student_class 中的一列。