数据库技术,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";