下面我来总结一下我以前所用到的SQL语句。排序不分先后,按照我现在整理的顺序输入。本来想加一些注释的,但是现在有的也就知道个大概,具体的要装几个数据库,比较麻烦。大家对照着输入查看结果应该就可以明白了。而且有的还有很多变化,大家具体的在去查看具体的文档对系统学习也有好处。按照当时所用的数据库系统分为以下几类:
一 Microsoft SQL Server
(1) select convert(char(8),getdate(),108)
应该是获取某种格式的数据库时间。用来与服务器同步,读同一时间用。
(2) select * from records where emid='"+userid+"' and reason in('"+Normal+"','"+Later+"') and YEAR(getdate())=YEAR(entertime) and MONTH(getdate())=MONTH(entertime) and DAY(getdate())=DAY(entertime) and datepart(hh,entertime)>=12
上面的entertime应该为数据库里的一个字段。语句是java里的SQL语句。
(3) select a.*,b.name from records a,employees b where a.emid=b.emid and a.reason in('迟到','缺勤') and a.entertime between '"+beginDate +"' and '"+endDate+"'
复合查询。
(4) select count(*) from records where entertime between '"+beginDate +"' and '"+endDate+"'
统计功能。
(5) delete well_data where wl_time<GETDATE()-10 and wl_move is null
数据库整理用的。删除多余的过期并没有用的数据库资料。
(6) backup database DBtest to disk='d:/DBtest .dat'
数据库备份
(7) restore database DBtest from disk=''d:/DBtest .dat'
恢复数据库
(8) backup log DBtest to disk='d:/DBtestLOG .dat'
备份数据库日志
二 Oracle
(1) select sysdate from dual;
三 MySQL
(1) select distinct a.PTNR_COMP_NAME,b.CHARGE_NAME,b.CHARGE_PWD,
b.CHARGE_AUTHORITY,b.CHARGE_ID,c.DECODE_VAL
from
MsProductCorp a,MsReceptCharge b,MsCode c
where a.PTNR_COMP_NO=b.PTNR_COMP_NO AND CHARGE_DEL_FLAG='{0}' AND
b.CHARGE_AUTHORITY=c.CODE_VAL AND CODE_NAME='{1}'
(2)select count(*) from fingerprinter group by finger order by count(*) desc