DB2数据库(Database)常用SQL查询(SELECT语句)命令

本文用[xxxxxx]表示一个变量在使用时需要用实际的数据进行替换

 

#一个最简单查询语句

select * from [tablename]

 

#带条件的查询语句

select * from [tablename] where [columnname] = [value]

 

#查询前n条数据

select * from [tablename] fetch [n] rows only

 

#查询第n条到第n+m数据,一般用于分页功能

select * from (select *, (rownumber() over(order by [columnname])) as rownum from [tablename]) as [tablealiasname] where rownum between [n] and [n+m]

 

#包含case的查询语句

db2 "select [col1], case when [col2]>0 then 1 when [col2]<0 then -1 else 0 end from [tablename]"

你可能感兴趣的:(sql,数据库,db2,database)