mysql中有列字段的值是依逗号隔开的,如何求和

mysql中有列字段的值是依逗号隔开的,如何求和

问题描述:

sql语句查出来的结果:

select money from ceshi where id=1;
结果:540.00,315.00,540.00,1080.00
如何不是用程序的情况下,直接使用mysql语句,将此结果中逗号隔开的数据
得到和 , 就是直接用sql查出来他们这几个值的he

可以在数据库中定义一个函数split_sum,功能是把字符串按照逗号分隔,然后相加,并返回结果。然后使用:

select split_sum(money) from ceshi where id=1;

select sum(money) from ceshi where id=1;

SQL 支持聚合函数的,了解下聚合函数,sum,avg,max ,min 等的基本知识。
http://blog.itpub.net/28777824/viewspace-2154273/

根据逗号截取 单行转多行,然后求和
搜到的例子:https://blog.csdn.net/csumathz/article/details/51888293