DB2中不同于其它数据库的操作
一、两个字段联接
select ID,LASTNAME||FIRSTNAME from T_EMPLOYEE DB2中用“||”来将两个字段联接起来 注意:不同于其它数据库中用"+"来将两个字段联接起来
二、查出前几条记录
如SQLSERVER中的TOP
select * from T_EMPLOYEE fetch first 3 rows only;
三、db2分页查询sql
select * from (
select ROW_NUMBER() OVER(ORDER BY DOC_UUID DESC) AS ROWNUM, DOC_UUID, DOC_DISPATCHORG, DOC_SIGNER, DOC_TITLE from DT_DOCUMENT ) a
where ROWNUM > 20 and ROWNUM <=30
四、ROW_NUMBER()函数
增加行号,不排序
select * from ( select ROW_NUMBER() OVER() AS ROWNUM,t.* from DT_DOCUMENT t ) a
增加行号,按某列排序
select * from ( select ROW_NUMBER() OVER( ORDER BY DOC_UUID DESC ) AS ROWNUM,t.* from DT_DOCUMENT t ) a
五、当前日期获取:current date (两个单词,中间有空格)
获取当前日期:current date
天的表示:days
select * from t_employee e where e.contract_date = current date + 51 days
六、取前几条数据:select * from t_role order by id desc fetch first 5 rows only