SELECT `user`.id AS`用户ID`, `user`.username AS`用户姓名`, Count(distinct person_url_relation.rel_person_id) AS`已标注患者总数`, Count(distinct person_trace.trace_id) AS`已标注轨迹总数`, Count(distinct url_info_second.url_id) AS`已分配的url数` FROM `user` LEFTJOIN url_info_second ON url_info_second.user_id = `user`.id LEFTJOIN person_url_relation ON person_url_relation.rel_url_id = url_info_second.url_id LEFTJOIN person_trace ON person_url_relation.rel_person_id = person_trace.person_id WHERE`user`.id > 14 GROUPBY `user`.id
v2:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
SELECT * FROM ( SELECT `user`.id AS user_id, `user`.username AS user_name, Count(distinct person_url_relation.rel_person_id) AS totalP, Count(distinct person_trace.trace_id) AS totalT, Count(distinct url_info_second.url_id) AS totalU FROM `user` LEFTJOIN url_info_second ON url_info_second.user_id = `user`.id LEFTJOIN person_url_relation ON person_url_relation.rel_url_id = url_info_second.url_id LEFTJOIN person_trace ON person_url_relation.rel_person_id = person_trace.person_id WHERE`user`.id > 14 GROUPBY `user`.id ) AS finshed_t WHERE finshed_t.totalU <> 0
统计第二次未完成标注的url数量:
1 2 3 4 5 6 7 8 9 10 11 12
SELECT`user`.id as'用户ID', IFNULL(k.unfinshed, 0) as'未完成标注的url数' FROM`user`LEFTJOIN ( SELECT url_info_second.user_id AS user_id, Count(distinct url_info_second.url_id) AS unfinshed FROM url_info_second WHERE url_condition = '待标注' GROUPBY url_info_second.user_id )AS k ON k.user_id = `user`.id WHERE`user`.id > 14
合并以上两个结果:[Err] 1248 - Every derived table must have its own alias
SELECT user_id1 AS`用户ID`, user_name AS`用户名`, totalP AS`已标注患者人数`, totalT AS`已标注轨迹总数`, totalU AS`已分配的url数`, unfinshed AS`未完成标注的url数` FROM ( SELECT * FROM ( SELECT * FROM ( SELECT `user`.id AS user_id1, `user`.username AS user_name, Count(distinct person_url_relation.rel_person_id) AS totalP, Count(distinct person_trace.trace_id) AS totalT, Count(distinct url_info_second.url_id) AS totalU FROM `user` LEFTJOIN url_info_second ON url_info_second.user_id = `user`.id LEFTJOIN person_url_relation ON person_url_relation.rel_url_id = url_info_second.url_id LEFTJOIN person_trace ON person_url_relation.rel_person_id = person_trace.person_id WHERE`user`.id > 14 GROUPBY `user`.id ) AS finshed_t WHERE finshed_t.totalU <> 0 )AS finshed LEFTJOIN ( SELECT * FROM ( SELECT`user`.id as user_id2, IFNULL(k.unfinshed, 0) as unfinshed FROM`user`LEFTJOIN ( SELECT url_info_second.user_id AS user_id, Count(distinct url_info_second.url_id) AS unfinshed FROM url_info_second WHERE url_condition = '待标注' GROUPBY url_info_second.user_id )AS k ON k.user_id = `user`.id WHERE`user`.id > 14 ) AS unfinished_url ) ON finished.user_id1 = unfinshed_url.user_id2 ) as t
统计失效url:待审核但无关联人员:
1 2 3 4 5 6 7 8 9 10 11 12 13
SELECT * FROM ( SELECT `user`.id AS user_id, `user`.username AS user_name, Count(distinct url_info_second.url_id) AS totalU FROM `user` LEFTJOIN url_info_second ON url_info_second.user_id = `user`.id WHERE`user`.id > 14 GROUPBY `user`.id ) AS finshed_t WHERE finshed_t.totalU <> 0
1 2 3 4 5 6 7 8 9 10 11 12
SELECT * FROM ( SELECT url_id, user_id, Count(distinct person_url_relation.rel_person_id) AS totalP FROM url_info_second LEFTJOIN person_url_relation ON person_url_relation.rel_url_id = url_info_second.url_id LEFTJOIN person_trace ON person_url_relation.rel_person_id = person_trace.person_id WHERE url_condition = '待审核' GROUPBY url_id ) AS u_p_count
创建 view 时,select 语句无法嵌套
存在问题的url数量:
1 2 3
SELECT user_id,COUNT(url_id) from url_person_count WHERE totalP = 0 GROUPBY user_id