易截截图软件、单文件、免安装、纯绿色、仅160KB

求一个mssql的sql语句 - MS-SQL Server / 基础类

判断表中是否有大于10条以上的数据,
如果存在则按最好录入的时间,删除掉多余的数据。。
保持数据表中只有10条最新的数据。。

谢谢。
select ID,count(1) from TB group by ID having count(1)>10


SQL code:
;with t as
(
select rn=row_number()over(order by date desc),*
from tb
)
select * from t where rn>10


SQL code:
if (select count(1) from [Table])>10
delete from [Table] where id not in(select top 10 id from [Table] order by 时间 desc)


SQL code:
if (select count(1) from tb)>10
delete from tb where id not in (select top 10 id from tb order by dt desc)


delete a from TB a
inner join 
(select * from (select ID,DT,row=row_number() over (patition by id order by dt desc) from TB)T where row>10) b
on a.id=b.id 
and a.DT=b.DT


SQL code:
if exists (select count(1) from tb)>10
begin
delete from tb where date not in (select top 10 date from tb order by date desc)
end


SQL code
{{


相关问答:

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

MS SQL作业问题 - MS-SQL Server / 应用实例

如何在SQL2005中设定定时作业,比如说定时清理某些表的数据,
或者是定时的将某些表的数据导出excel!
在线等待,急急急,最好是详细步骤!
之前我做的作业有点问题!
帮UP

参考:http://hi.baidu.com/toiota ......

求一SQL - MS-SQL Server / 基础类

tab1 字段:billdate,goodsid,incount,inmoney,outcount,outmoney,endprice,endcount,endamt
tab2 字段:goodsid,goodskind(商品类型)
tab3 字段:goodskind(商品类型),kindname
结果:
得到商品类型在一段时间 ......

sql 问题 - MS-SQL Server / 基础类

需求如下:
学院 academy(aid,aname)
班级 class(cid,cname,aid)
学生 stu(sid,sname,aid,cid)
住宿区 region(rid,rname)
宿舍楼 build(bid,rid,bnote) bnote是‘男’/‘女’
宿舍 dorm(did,rid,bid,bedn ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号