MySQL关联查询count总数

select c.customid,c.headurl,c.nickname,c.working_years,c.remarks,c.certificate,
t.countTask,w.countWorks
FROM custom_info c

left join (select count(custom_id) as countTask,custom_id from task_info where project_status = 3 GROUP BY custom_id) t on c.customid = t.custom_id 
left join (select count(customid) as countWorks,customid  from works_info where original_type = 0 and auditing_status = 1 GROUP BY customid) w on c.customid = w.customid 
where custom_status = 1
ORDER BY c.customid

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL中,可以使用关联查询count()函数来统计总数。首先,你需要使用LEFT JOIN或INNER JOIN将两个表关联起来。然后,使用count()函数对需要统计的字段进行计数。下面是一个示例查询语句: SELECT COUNT(*) FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id; 其中,table1和table2是需要关联的两个表,id是它们之间的关联字段。这个查询将返回两个表关联后的总数。 如果你需要在关联查询中统计某个字段的数量,可以使用以下语句: SELECT t1.field, COUNT(t2.field) FROM table1 t1 JOIN table2 t2 ON t1.id = t2.id GROUP BY t1.field; 其中,field是需要统计的字段。这个查询将返回每个table1中的field值以及与之关联的table2中field的数量。 请注意,根据你的具体需求,你可能需要根据实际情况进行适当的修改。 #### 引用[.reference_title] - *1* *3* [MySQL关联查询 COUNT数据不准确](https://blog.csdn.net/weixin_42313773/article/details/127253892)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [mysql 根据统计子查询总数,修复关联父查询总数](https://blog.csdn.net/Lixuanshengchao/article/details/114873956)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值