Mysql merges values of the same column. mysql merges values of the same column.
I have the following query conditions:
I want the final display Effect
Merge group_name with the same id into one row. Implementation Method: add the keyword group_concat before group_name. Then add the group by id at the end of the SQL statement.
Group_concat can separate the values of the same column by commas and form a string. (Mysql)
The SQL statement in the first figure is as follows:
SELECT tr. id, tig. group_name FROM tj_record tr
Inner join tj_item_group_ex tige ON tr. id = tige. record_id
Inner join tj_item_group tig ON tige. id = tig. id
WHERE tr. id IN ('20140901', '20160901') AND tige. id IN ('27', '31 ')
The SQL statement in the second figure is as follows:
SELECT tr. id, GROUP_CONCAT (tig. group_name) FROM tj_record tr
Inner join tj_item_group_ex tige ON tr. id = tige. record_id
Inner join tj_item_group tig ON tige. id = tig. id
WHERE tr. id IN ('20140901', '20160901') AND tige. id IN ('27', '31 ')
Group by tr. id
The red marked red is the difference. In this case, you do not need to splice strings one by one in the background.
Mysql merges records with the same field values in a table.
Select m1, sum (m2) from ABC group by m1;
How does Mysql merge column values?
SELECT GROUP_CONCAT (name SEPARATOR '') AS name FROM