有什么规则?自己加条件就行了。SELECT * FROM TableName WHERE ...^_^
解决方案 »
- sql(求和)碰到的问题
- 大容量数据库的完整性备份问题
- 请教一个关于 alter database的问题。
- sqlserver2005的备份用sqlserver2000怎么还原啊,已经有了2005的备份但那个机子上只有2000的
- 用高级语言实现sql中的基本语句,求指点。
- 为什么在存储过程中不能建立临时表?
- 急用!!谁有用"V Foxpro 6.0"开发的“图书馆管理系统”?
- 如何用SQL生成2006110901这样的表示日期时间的字符串,并增加一递增数据01
- 我有一个横排的表现在想把他变成纵排的!来帮我啊!5555在线等!~~~~~~~~~~~
- 如何与realtop联系,询问具体方法?
- 经理的一个问题?
- 从visio生成数据库的问题
select a.*
from T1 a, (select mainid, max(date) date from T1 group by mainid)b
where a.mainid=b.mainid and a.date=b.date
select * from table1 where date in (select max(date) date from table1
group by mainid ) order by id
where not exists(select 1 from T1 where mainid=t.mainid and datediff(day,t.[date],[date])>0)
create table T1
(
ID int,
mainid int,
[date] varchar(10),
bz varchar(10)
)
insert T1
select 1,1,'2005-1-1','bz1' union
select 2,1,'2005-2-1','bz2' union
select 3,2,'2005-1-1','bz3' union
select 4,2,'2005-7-1','bz4' union
select 5,2,'2005-6-1','bz5'--测试
select * from T1 t
where not exists(select 1 from T1 where mainid=t.mainid and datediff(day,t.[date],[date])>0)--删除测试环境
drop table T1--结果
/*
ID mainid date bz
----------- ----------- ---------- ----------
2 1 2005-2-1 bz2
4 2 2005-7-1 bz4(所影响的行数为 2 行)
*/