SQL 两个时间段问题
数据库字段
Time
2009-12-1
2009-11-1
2009-9-1
2009-10-1
2008-1-1
2008-12-1
2008-11-1
2008-10-1
2008-9-1
2007-5-1
查询出时间段为2009-10-1到2009-11-1 以及 2008-10-1到2008-11-1
就是去年和今年的同一时间段的记录
列如:用户想看2009年9月到2009年12月记录(不会跨年) 并显示去年的9月到12月的记录
查询结果应为
2009-12-1
2009-11-1
2009-9-1
2009-10-1
2008-12-1
2008-11-1
2008-10-1
2008-9-1
试过between and 但是只能出一个时间段 根据用户输入的 生成后一个时间段 year-1
但是问题是中间用and 和 or都有问题 , 请教各位SQL高手
SQL code:
declare @dt1 as datetime
declare @dt2 as datetime
set @dt1 = '2009-09-01'
set @dt2 = '2009-12-31'
select * from tb where time between @dt1 and @dt2 or time between datename(yy,@dt1) + right(convert(varchar(10),@dt1,120),6) and datename(yy,@dt2) + right(convert(varchar(10),@dt2,120),6)
SQL code:
create table tb(Time Datetime)
insert tb select
'2009-12-1' union all select
'2009-11-1' union all select
'2009-9-1' union all select
'2009-10-1' union all select
'2008-1-1' union all select
'2008
相关问答:
表如下
教室ID 座位数 开始时间 结束时间 2009年1月1日 2009年1月2日 2009年1月3日
101 50 08:00 08:30 30 40 50
101 50 09:00 ......
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
请问一下,外网两台SQLSERVER实例数据传输,有没有采用数据压缩和加密。压缩比是多少,加密是什么加密算法?相关文档哪里可以找到?谢谢
我也想知道!关注此贴!
关注~~
数据库大牛都哪去了啊?
......
我要得到一个字符串如:
sdfk|||sgts
sdfsfd|||rgreg
wrfw|||sefw
就是要得到|||后面的字符串,有什么函数吗?怎么用呢?谢谢!
SQL code:
select
right(col,len(col)-charindex('|||',col)-2)
f ......
大家好,我最近维护一个项目,100多个表
只能用jdbc直连
遇到了多个表 关联 查询的情况 请大家指教
比如
student(studentid,classid)
class(classid,classname)
class_teacher(classid,teacherid)这个是中间表 ......