1 限制结果表大小 Select * from tabname fetch first 5 rows only; 2 cast 用法 Select * from tabnameA where coln = cast( ‘TR01’ as tabnameB) CAST(salary AS DOUBLE) 类型转换 3 连接 内连接 selet a.col,b.col from tab a,tab b where a.t1=b.t1; 外连接: 左连接:select a.col,b.col from tab a left join tab b on a.t1=b.t1 (left outer join) 右连接: 4 输出排序 Order by col DESC 降序排列 缺省为升序 5 限制输出结果,与order 共用 Select * from tabA order by col desc fetch first 5 rows only 6 su bstr 函数 Substr(col,1,2); col 为char 或varchar 型 7 列函数 可以参照数据库中FUNCTIONS 中的说明 用Quest Centeral 查看,以下是常用的 Max 、avg、 count… DB2 中的VARCHAR 转换为INTEGER 的函数为CAST() DB2 中的INTEGER 转换为VARCHAR 的函数为CHAR() DB2 中的VARCHAR 转换为DATE 的函数为DATE() DB2 中的DATE 转换为VARCHAR 的函数为CHAR() char(col,iso) 输出yyyy-mm-dd YEAR() 返回 date 数值的年部分 Month()返回 date 数值的月部分 HOUR() 返回一个数值的小时部分 SELECT HOUR('18:34:23')FROM SECOND() 返回一个数值的秒部分 RTRIM()删除字符串尾部的空格 Ltrim()删除字符串左边的空格 Replace(col,ex p1,ex p2)替换col 中ex p1 为ex p2 MOD(EXP1,EXP2) 返回 EXP1 除以EXP2 的余数 DOUBLE()如果参数是一个数字表达式,返回与其相对应的浮点数,如果参数是字符串表达式,则返回该数的字符串表达式. FLOAT() 返回一个数的浮点表示 FLOOR() 返回小于或等于参数的最大整数 8 group by分组 Select a, sum(fse) from tab group by a having sum(fse)>1000 Having 过滤条件 9 取消重复值 distinct Select distinct col from tab 10 字符串匹配 like 11 范围查找 between and 12 否定条件查找 not like 13 空值查询 col is null 14 查找一组值 col in (1,2); 15 子查询 Select * from tabA where col1 in (select col from tabB); Select * from tabA where col1 not in (select col from tabB); 16 case 表达式 Select case When score < 65 then ‘not passed’ When score<...