位置:首页 > 网络编程 > 数据库
点击展开栏目简介
数据库技术,mysql,oracle

oracle:case when实现单条语句获取不同where条件下的count功能

分享到: 微信 新浪微博 更多

分步获取:

$sql1="select count(*) countall from visit_looyu_chat where 1=1";

$sql2="select count(*) countuser from visit_looyu_chat where 1=1 and chat_startmode=2";

$sql3="select count(*) countavail from visit_looyu_chat where 1=1 and chat_usermsgcount>0 and chat_viewermsgcount>0";


使用case when:

$sql="select count(*) countall
,sum(case when chat_startmode=2 then 1 else 0 end) as countuser
,sum(case when chat_usermsgcount>0 and chat_viewermsgcount>0 then 1 else 0 end) as countavail
from visit_looyu_chat";


上篇:oracle:操作自身带单引号的数据时处理方法

下篇:oracle:like模糊查询的优化

发表评论 ​共有​条评论
  • 匿名发表