mysql统计数据表中同一字段不同状态的COUNT()语句

   public function getDevice()
    {
        global $db, $res;
        dbc();
        $sql = "select COUNT(imei) AS total,COUNT(CASE state WHEN '1' THEN 1 END) AS highState,COUNT(CASE state WHEN '-1' THEN -1 END) AS lowState,COUNT(CASE state WHEN '0' THEN 0 END) AS normalState from " . $db->table('info');
        $row = $db->queryall($sql);
        $res["data"] = $row;
        die(json_encode_lockdata($res));
    }

Done!

©️2020 CSDN 皮肤主题: 精致技术 设计师:CSDN官方博客 返回首页