1、获取查询记录第n行
【sqlserver】
select top 1 * from customer t1
where t1.UserName not in
(select top 1 t2.UserName from customer t2) --查询第2行数据
如下图所示:
【mysql】
select * from customer limit 1,1
【oracle】
select * from customer t1
where t1.UserName not in
(select t2.UserName from customer t2 where rownum <=1) and rownum <=1;
2、获取字符串包含某字符数量
思路:“原字段”总长度 减去“查询字段” 替换为空后的长度。
select ( len(UserName) - len( replace(UserName,'0','') ) ) 零的个数from customer;
如下图所示:
【mysql】
select ( length(UserName)-length(replace(UserName,'0',''))) 个数
from customer;
【oracle】 select NVL( ( length(UserName)-length(replace(UserName,'0',''))),length(UserName)) 个数
from customer;
【注意】:在oracle中,如果 字符串 都是该字符,则获取到的为空,而不是个数。所以需添加 NVL 判断