首页统计柱状图
作者:互联网
SELECT
count( userPhone ) AS userCount,
organizationId,organizationName
FROM
(
SELECT
a.userPhone,
a.organizationId,
o.organizationName,
hr.questionnaireId
FROM
(
SELECT
userPhone,
organizationId
FROM
(
SELECT
userPhone,
organizationId
FROM
user_info UNION
SELECT
userPhone,
organizationId
FROM
user_info_sub_workers UNION
SELECT
userPhone,
organizationId
FROM
user_info_own_workers
) ui
WHERE
ui.organizationId IN ( SELECT organizationId FROM organization WHERE parentId = 795)
) a
LEFT JOIN organization o ON a.organizationId = o.organizationId
LEFT JOIN (
SELECT max( healthRecordId ) AS healthRecordId,phone, name, MAX(createTime), expiredTime,organizationId,questionnaireId
FROM health_record
WHERE 1=1
AND organizationId IN ( SELECT organizationId FROM organization WHERE parentId = 795)
-- and expiredTime > CURRENT_TIMESTAMP ()
GROUP BY
phone
) hr ON a.userPhone = hr.phone
WHERE
hr.healthRecordId IS NOT NULL
) b
GROUP BY organizationId
、、、
SELECT 0 AS writeCount, a.organizationName, a.questionnaireName, concat( a.organizationId, '-', a.questionnaireId ) AS id, CASE WHEN b.userCount IS NULL THEN 0 ELSE b.userCount END AS unWriteCount FROM (SELECT qc.organizationId,o.organizationName,hq.questionnaireId,hq.questionnaireName FROM ( SELECT * FROM questionnaire_config WHERE organizationId IN ( SELECT organizationId FROM organization WHERE parentId = 795 ) ) qc LEFT JOIN health_questionnaire hq ON qc.questionnaireId = hq.questionnaireId LEFT JOIN organization o ON qc.organizationId = o.organizationId ) a LEFT JOIN ( SELECT count( DISTINCT userPhone ) AS userCount, ui.organizationId FROM( SELECT userPhone, organizationId FROM user_info UNION SELECT userPhone, organizationId FROM user_info_sub_workers UNION SELECT userPhone, organizationId FROM user_info_own_workers ) ui WHERE ui.organizationId IN ( SELECT organizationId FROM organization WHERE parentId = 795 ) GROUP BY ui.organizationId ) b ON a.organizationId = b.organizationId
再有
SELECT * FROM health_record where phone='18883128818'
SELECT * FROM health_record where questionnaireId=817 order by createTime DESC
SELECT userPhone, organizationId
FROM user_info where userPhone in
(
SELECT phone
FROM health_record
WHERE healthRecordId IS NOT NULL
AND organizationId IN ( SELECT organizationId FROM organization WHERE parentId = 795)
GROUP BY phone
) -- AND organizationId=796
SELECT count( userPhone ) AS userCount, organizationId FROM ( SELECT a.userPhone, a.organizationId, hr.questionnaireId FROM ( SELECT userPhone, organizationId FROM ( SELECT userPhone, organizationId FROM user_info ) ui WHERE ui.organizationId IN ( SELECT organizationId FROM organization WHERE parentId = 795) ) a LEFT JOIN ( SELECT max( healthRecordId ) AS healthRecordId,phone, name, MAX(createTime), expiredTime,organizationId,questionnaireId FROM health_record WHERE 1=1 AND organizationId IN ( SELECT organizationId FROM organization WHERE parentId = 795) -- and expiredTime > CURRENT_TIMESTAMP () GROUP BY phone ) hr ON a.userPhone = hr.phone LEFT JOIN health_questionnaire hq ON hr.questionnaireId = hq.questionnaireId WHERE hr.healthRecordId IS NOT NULL AND hq.organizationId = 795 ) b GROUP BY organizationId
标签:organizationId,统计,questionnaireId,hr,柱状图,userPhone,首页,WHERE,SELECT 来源: https://www.cnblogs.com/hogeisok/p/16433321.html