Home > Database > Mysql Tutorial > mysql相同内容的字段合并为一条的方法_MySQL

mysql相同内容的字段合并为一条的方法_MySQL

WBOY
Release: 2016-06-01 13:42:17
Original
898 people have browsed it

bitsCN.com
mysql相同内容的字段合并为一条的方法_MySQL
 从两个表中内联取出的数据,其中category_name字段有相同内容,想将具有相同内容的字段进行合并,将amount字段进行加法运算,变成下表中的内容 mysql相同内容的字段合并为一条的方法_MySQL SELECT c.category_name, count(*) AS task_num, sum( t.amount ) AS amount_numFROM cs_witkey_tasks AS t    INNER JOIN cs_witkey_category AS c ON t.category_id = c.cidGROUP BY c.category_name DESC 应该用group by而不是order by。   作者 岳冠群 bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template