以下均针对oracle数据库,与mysql、sqlserver或有出入,欢迎共同交流
1、查找符合条件的记录数,查不到时显示为0而不是返回null
select case count(id) when 0 then 0 else count(id) from 表名 where xx=xx
2、查询符合某件数字字段 所占整体的百分比 并保留两位小数
例:11.11%
select CONCAT(to_char(sum(字段名)/(select sum(字段名) from 表名)*100,'fm9999990.00'),'%') baifenbi from 表名where xx='xx'
3、查询某个时间段内的数据
select * from 表名where 字段名 between to_date('2018-1-1','yyyy-MM-dd') and to_date('2018-10-23','yyyy-MM-dd')
4、按照指定顺序查询
select * from 表名 order by DECODE(字段名,'AA',1,'BB',2,'CC',3);
//按照 AA BB CC 的顺序排序 如果字段是数字则直接DECODE(字段名,1,2,3); 就可以了
待更。。。。