资源描述:
《plsql常用语句》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、说明:复制表(只复制结构,源表名:a新表名:b)SQL:select*intobfromawhere1<>1说明:拷贝表(拷贝数据,源表名:a目标表名:b)SQL:insertintob(a,b,c)selectd,e,ffromb;说明:显示文章、提交人和最后回复时间SQL:selecta.title,a.username,b.adddatefromtablea,(selectmax(adddate)adddatefromtablewheretable.title=a.title)b说明:外连接查询(表
2、名1:a表名2:b)SQL:selecta.a,a.b,a.c,b.c,b.d,b.ffromaLEFTOUTJOINbONa.a=b.c说明:日程安排提前五分钟提醒SQL:select*from日程安排wheredatediff('minute',f开始时间,getdate())>5说明:两张关联表,删除主表中已经在副表中没有的信息SQL:deletefrominfowherenotexists(select*frominfobzwhereinfo.infid=infobz.infid)说明:--SQL
3、:SELECTA.NUM,A.NAME,B.UPD_DATE,B.PREV_UPD_DATEFROMTABLE1,(SELECTX.NUM,X.UPD_DATE,Y.UPD_DATEPREV_UPD_DATEFROM(SELECTNUM,UPD_DATE,INBOUND_QTY,STOCK_ONHANDFROMTABLE2WHERETO_CHAR(UPD_DATE,'YYYY/MM')=TO_CHAR(SYSDATE,'YYYY/MM'))X,(SELECTNUM,UPD_DATE,STOCK_ONHAN
4、DFROMTABLE2WHERETO_CHAR(UPD_DATE,'YYYY/MM')=TO_CHAR(TO_DATE(TO_CHAR(SYSDATE,'YYYY/MM')¦¦'/01','YYYY/MM/DD')-1,'YYYY/MM'))Y,WHEREX.NUM=Y.NUM(+)ANDX.INBOUND_QTY+NVL(Y.STOCK_ONHAND,0)<>X.STOCK_ONHAND)BWHEREA.NUM=B.NUM说明:--SQL:select*fromstudent
5、infowherenotexists(select*fromstudentwherestudentinfo.id=student.id)and系名称='"&strdepartmentname&"'and专业名称='"&strprofessionname&"'orderby性别,生源地,高考总成绩说明:从数据库中去一年的各单位电话费统计(电话费定额贺电化肥清单两个表来源)SQL:SELECTa.userper,a.tel,a.standfee,TO_CHAR(a.telfeedate,'yyyy')ASte
6、lyear,说明:四表联查问题:SQL:select*fromaleftinnerjoinbona.a=b.brightinnerjoincona.a=c.cinnerjoindona.a=d.dwhere.....说明:得到表中最小的未使用的ID号13SQL:SELECT(CASEWHENEXISTS(SELECT*FROMHandlebWHEREb.HandleID=1)THENMIN(HandleID)+1ELSE1END)asHandleIDFROMHandleWHERENOTHandleIDIN
7、(SELECTa.HandleID-1FROMHandlea)查找重复的记录select*fromfishwherefish_namein(selectfish_namefrom(selectfish_name,count(fish_name)fromfishgroupbyfish_namehavingcount(fish_name)>1));统计某字段中所有不同的记录的个数selectnsrbm,count(nsrbm)fromt11_nsrjbqkwhere...groupbynsrbmhavingc
8、ount(nsrbm)>1SELECT*FROMlettersWHERE((.IDIN(SELECTIDFROMlettersAsTmpGROUPBYIDHAVINGCount(*)>1)))ORDERBYID;在SQLEnterpriseManager裡面查詢Access裡面的數據SELECT*FROMOPENROWSET('msdasql','dsn=odbc數據源名;trusted_connection=yes','se