首页 > 代码库 > (MYSQL学习笔记3)mysql两行数据合并成一行
(MYSQL学习笔记3)mysql两行数据合并成一行
使用SUM函数,加上GROUP BY人员ID就可以实现了:
SELECT SUM(PZ+CPJS+BZ+GC+SB+TG+MJ+CL+CCLW+GJ+ZL+CBZZ) as count, SUM(PZ) as PZ,SUM(CPJS) as CPJS,SUM(BZ) as BZ,SUM(GC) as GC,SUM(SB) as SB,SUM(TG) as TG,SUM(MJ) as MJ,SUM(CL) as CL,SUM(CCLW) as CCLW,SUM(GJ) as GJ,SUM(ZL) as ZL,SUM(CBZZ) as CBZZ,SUM(YHID) as YHID,SUM(DJRMC) as DJRMC FROM tableName WHERE YHID=‘$ID‘ AND NF=‘$NF‘ GROUP BY YHID;
本文出自 “w1sw” 博客,请务必保留此出处http://cfdeng.blog.51cto.com/9873532/1944324
(MYSQL学习笔记3)mysql两行数据合并成一行
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。