表结构:如下

mysql用一条sql统计某个字段不同值的个数

 

实现的sql语句:

SELECT a.name,a.address,a.leader_name,a.leader_phone,COUNT(type) sum,SUM(case when b.type=0 then 1 else 0 end) buyer,SUM(case when b.type=1 then 1 else 0 end) seller FROM village_shop a left JOIN Village_operation2 b ON a.id=b.village_id  WHERE `op_id` = '12' GROUP BY b.village_id

结果:

 mysql用一条sql统计某个字段不同值的个数

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-20
  • 2022-01-13
  • 2021-11-11
相关资源
相似解决方案