解决方案 »
- Lumigent Log Explorer出现No log recorders found that match the filter
- 有关Top和ASCII的使用问题!
- 再求一条和刚问过的类似的SQL语句
- 思考帖
- 想做数据库这块,相关人士请帮忙!谢谢
- 如何获取表的列数?
- 数据库安装到最后一步在配置和启动服务器时失败,请高手帮忙
- 存储过程使用临时表为何出错!
- 使用sql server建立了一个链接服务器,为何表,视图中无内容,我明明通过验证,而且服务器处有表和视图.
- SQL Server 2008 r2 awe 出错(报17128)无法使用
- 这个distinct有点迷糊,
- 查寻两表三字段都相等
drop table tb
Go
Create table tb([t11] Datetime,[t12] Datetime,[t21] Datetime,[t22] Datetime,[t31] Datetime,[t32] Datetime,[t41] Datetime,[t42] Datetime)
Insert tb
select '2010-2-1','2010-2-6','2010-2-7','2010-2-13','2010-2-14','2010-2-20','2010-2-21','2010-2-28' union all
select '2010-3-1','2010-3-6','2010-3-7','2010-3-13','2010-3-14','2010-3-20','2010-3-21','2010-3-27' union all
select '2011-3-28','2010-4-3','2010-4-4','2010-4-10','2010-4-11','2010-4-23','2010-4-24','2010-4-30'
Go
select 区间,
[t11]首日期
from
(
Select [t11],
[t12],
'[t11-t12]'区间
from tb
union all
Select [t21],
[t22],
'[t21-t22]'区间
from tb
union all
Select [t31],
[t32],
'[t31-t32]'区间
from tb
union all
Select [t41],
[t42],
'[t41-t42]'区间
from tb
)t
where '2010-3-16' between [t11]and [t12]
/*
区间 首日期
--------- -----------------------
[t31-t32] 2010-03-14 00:00:00.000(1 個資料列受到影響)
*/