mysql sum函数配合 case when distinct 去重复求和_JavaGirl_亚兰的博客-CSDN博客_sum去重求和

 SELECT  sum(DISTINCT case when  t1.id  then t1.amount else 0 end ) as t1sumAmount        from  table1 t1 left join table2 t2 on t1.id = t2.t1_id

如果t1对应多个t2,会出现t1的数量重复相加的情况,用上面的方式可去除重复


原网址: 访问
创建于: 2022-06-24 09:26:35
目录: default
标签: 无

请先后发表评论
  • 最新评论
  • 总共0条评论