Name DateTime
----------------------------------
a 2006-12-15 8:00:00
b 2006-12-15 9:00:00
c 2006-12-15 10:00:00
d 2006-12-15 9:00:00
e 2006-12-15 4:00:00查询最早时间和最晚时间,有下面的结果:
Name DateTime
----------------------------------
c 2006-12-15 10:00:00
e 2006-12-15 4:00:00
----------------------------------
a 2006-12-15 8:00:00
b 2006-12-15 9:00:00
c 2006-12-15 10:00:00
d 2006-12-15 9:00:00
e 2006-12-15 4:00:00查询最早时间和最晚时间,有下面的结果:
Name DateTime
----------------------------------
c 2006-12-15 10:00:00
e 2006-12-15 4:00:00
解决方案 »
- 急 查询问题
- 把字符串转化为整数的问题
- visual studio 2005 中自带的SQL怎么用啊?
- 求救:问题出在那儿?
- SELECT bs FROM dbo.bs WHERE bssx like %a group by bs ORDER BY bs 这样的查询大概三十万的数据行如何用索引优化一下...谢谢大哥们
- 怎么把SQL中一个分割函数的查询,改成存储过程呢??? ~~ 有完整代码,改成存储过程就好了~ 求助求助求助求助求助求助求助求助求助求
- 求教如何用report加for语句打印指定的记录?
- 请教ref cursor的使用,使用out参数能否返回查询结果集?
- 为什么我的98报告ODBC不支持动态Recordset?假如是驱动的问题,应该如何解决?
- 关于事务控制,还有一点就搞定了,大家帮忙,在线。
- 关于datetime。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
- 一个SQL语句的写法,我想了好久,没能实现??请教一下大家,谢谢
Union ALL
select NAME ,MIN(DateTime) From Table1
where no exists(select 1 from tablename where name = t1.name and datetime < t1.datetime)
or no exists(select 1 from tablename where name = t1.name and datetime > t1.datetime)
insert T select 'a', '2006-12-15 8:00:00'
union all select 'b', '2006-12-15 9:00:00'
union all select 'c', '2006-12-15 10:00:00'
union all select 'd', '2006-12-15 9:00:00'
union all select 'e', '2006-12-15 4:00:00'
select * from T
where [DateTime] in
(select min([Datetime]) from T
union
select max([Datetime]) from T)Name DateTime
---- ------------------------------------------------------
c 2006-12-15 10:00:00.000
e 2006-12-15 04:00:00.000(2 row(s) affected)