Username: Password:

精妙SQL语句介绍-数据库专栏,SQL Server
来源:作者: 发布时间:2007-12-25 13:47:57

sql: select * into b from a where 1<>1   
 

  说明:拷贝表(拷贝数据,源表名:a 目标表名:b)

 

  sql: insert into b(a, b, c) select d,e,f from b;   

 

  说明:显示文章、提交人和最后回复时间

 

  sql: select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b  

 

  说明:外连接查询(表名1:a 表名2:b)

 

  sql: select a.a, a.b, a.c, b.c, b.d, b.f from a left out join b on a.a = b.c   

 

  说明:日程安排提前五分钟提醒

 

  sql: select * from 日程安排 where datediff(minute,f开始时间,getdate())>5   

 

  说明:两张关联表,删除主表中已在副表中没有的信息

 

  sql:

 

  delete from info where not exists ( select * from infobz where info.infid=infobz.infid )   

 

  说明:--

 

  sql:

 

  select a.num, a.name, b.upd_date, b.prev_upd_date from table1,(select x.num, x.upd_date, y.upd_date prev_upd_date from (select num, upd_date, inbound_qty, stock_onhand from table2 where to_char(upd_date,yyyy/mm) = to_char(sysdate, yyyy/mm)) x, (select num, upd_date, stock_onhand from table2 where to_char(upd_date,yyyy/mm) = to_char(to_date(to_char(sysdate, yyyy/mm) ¦¦ /01,yyyy/mm/dd) - 1, yyyy/mm) ) y, where x.num = y.num (+)and x.inbound_qty + nvl(y.stock_onhand,0) <> x.stock_onhand ) b where a.num = b.num   

 

  说明:--

 

  sql:

 

  select * from studentinfo where not exists(select * from student where studentinfo.id=student.id) and 系名称="&strdepartmentname&" and 专业名称="&strprofessionname&" order by 性别,生源地,高考总成绩

喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅