t1
date id
2008-02-26 09:46:37.737 139 46000
2008-02-26 20:22:28.357 139 46000 t2 id
46000 结果 2008-02-26 09:46:37.737 139 46000
date id
2008-02-26 09:46:37.737 139 46000
2008-02-26 20:22:28.357 139 46000 t2 id
46000 结果 2008-02-26 09:46:37.737 139 46000
解决方案 »
- 最近防火墙总是提示有人通过1433端口连接我的MSSQL。。
- bcp导入数据问题,表中有自增列为主键
- 求查询语句
- 小问题一个...哪位进来告诉我一下这个语句是什么意思?
- 请教一个关于数据库连接的问题,应该很简单
- 请问:关于视图和普通基表查询的问题效率问题……???
- vfp中用什么函数可以调用浏览文件对话框?thx:)
- 那为大侠能告诉小弟:如何把Access的数据库转换为SQL SERVER,小弟一定给分,谢谢!请详细一点,再次感谢!
- 请问,知道起始日期和结束日期,怎么循环生成各个日期到数据库中。
- 这个SQL问题怎么解决 一群乱代码
- 求教。sql2000,sql2005中分别是如何实现自动备份数据库的~
- 如何取当前时间的上个季度?
select *
from T1 a
where not exists(select 1 from T1 where imsi= a.imsi and timeStamp>a.timeStamp)取得的是时间最大的一条。这条语句理解上应该是时间最小才对阿,
from t1 inner join t2 on t1.id=t2.id
group by t2.id[align=center]==== 思想重于技巧 ====
[/align]
declare @a table(date int ,ID int)
insert into @a select 100,5
insert into @a select 175,5
insert into @a select 175,6
insert into @a select 220,6declare @b table(ID int)
insert into @b select 5
insert into @b select 6
--最小
select a.id,min(date)
from @a a inner join @b b on a.id=b.id
group by a.id
--最大
select a.id,max(date)
from @a a inner join @b b on a.id=b.id
group by a.id
--第一条
select c.*
from (select a.* from @a a where date=(select top 1 date from @a b where ID=a.ID )) c
inner join @b b on c.id=b.id
--随机一条
select c.*
from (select a.* from @a a where date=(select top 1 date from @a b where ID=a.ID order by newid())) c
inner join @b b on c.id=b.id
select top 1 * from t1 join t2 on t1.id = t2.id order by t1.date
declare mycursor cursor for
select date,id from t1
open mycursor
fetch NEXT from mycursor into @date,@id
select t1.id,t1.date from t1 join t2
on t1.id=t2.id
where t1.date=@date and t1.id=@id
close mycursor
deallocate mycursor不太懂你要实现这个做什么,但我这样是能实现
select a.* from t1 a ,t2 b
where a.id=b.id and not exists(select 1 from t1 c where a.id=c.id and a.date<c.date)