Exists,Datediff,Newid,

来源:互联网 发布:360云盘mac版 编辑:程序博客网 时间:2024/05/01 02:52

---两张关联表,删除主表中已经在副表中没有的信息
delete from table1 where not exists ( select * from table2 where table1.field1=table2.field1 )

---日程安排提前五分钟提醒
SQL: select * from 日程安排 where datediff('minute',f开始时间,getdate())>5

---随机取出10条数据
select top 10 * from tablename order by newid()

-- 类似有 month day year
select * from table1   where convert(varchar,date,120) like   '2006-04-01%' 
--datediff
select * from table1   where datediff(day,time,'2006-4-1')=0

原创粉丝点击