原!!如何将多个复杂查询整合成一个查询,并作为一个对象的各个字段输出
近期web开发后台运营管理,涉及相关数据展示,如图所示:
里面的大部分查询都是涉及多表的复杂查询,那么如何将这些查询整合成一个查询,并作为一个对象的各个字段?
例子:前端showObject对象成员属性:regUserNum,createPrjUserNum,createPrjUserTimes,
SELECT
(SELECT scr.CO_TYPE1_SHORT from stat_company_relation
scr WHERE
scr.CMCCIWMS_CO_NAME LIKE
CONCAT('%','${参数名}','%')) as companyType,
(SELECT COUNT(*) from iw_user u WHERE u.proComany
LIKE
CONCAT('%','${参数名}','%')) as regUserNum,
(SELECT COUNT(
DISTINCT
p.userid) as
'创建项目人数' FROM project p
LEFT JOIN iw_user u ON
p.userid=u.id
where
p.type=0 AND u.proComany LIKE
CONCAT('%','${参数名}','%')) as createPrjUserNum,
(SELECT
COUNT(p.userid) as '创建项目人次' FROM project p
LEFT JOIN iw_user u ON
p.userid=u.id
where p.type=0 AND u.proComany LIKE
CONCAT('%','${参数名}','%')) as createPrjUserTimes