此处:sid为学生学号,我想用一条sql语句实现如下功能
每年8月前,毕业班(如这里2013级)可以查询显示,8月后就查询出来不显示。
比如这里2019年8月后就不显示2013开头的学号了,2020年就不显示2014开头的学号了
求助!!
数据库为access
不知道sid的类型是int还是nvarchar
如果是int,那么
select * from team_manage where sid > 20140000
如果是char,那么
select * from team_manage where not(sid like '2013%')
select * from team_manage where sid like case when Getdate()<'2019-08-01' then ''2013% when getdate()>'2019-08-01' and getdate()<'2020-01-01' then '2014%' then getdate()>'2020-01-01' then '2015%' end
一般条件判断用case when 语句实现。可以参考case when 的用法。
sqlserver的语法不知道一样不,另外不知道sid是什么类型的,这边当int写的,给你参考下
select * from team_manage
where SUBSTRING(convert(varchar(10),sid),1,4)> =datepart(yy,getdate())-5-case when datepart(MM,getdate())>8 then 0 else 1 end
select * from team_manage where (DATENAME(YYYY,GETDATE())- cast(substring(sid,0,5) as int)<6)
这个是sqlserver的写法,不知道access是不是可以。
另外最后面的那个6就是只要6年内的数据