1. The grouping field is merged from multiple lines into one line.
mysql> select user_id,tag_id from yyfax_user.user_tag where user_id=‘U000412280’;
+------------+----------+
| user_id | tag_id |
+------------+----------+
| U000412280 | TAG20000 |
| U000412280 | TAG20002 |
| U000412280 | TAG50001 |
+------------+----------+
3 rows in set (0.00 sec)
mysql> select user_id,GROUP_CONCAT( tag_id SEPARATOR',') AS tag_id from yyfax_user.user_tag where user_id='U000412280';
+------------+----------------------------+
| user_id | tag_id |
+------------+----------------------------+
| U000412280 | TAG20000,TAG20002,TAG50001 |
+------------+----------------------------+
1 row in set (0.00 sec)
2. Sort the query results in the order specified by the field.
mysql> select user_id,create_time from yyfax_user.user_info where user_id in ('400','600',' 100');
+---------+---------------------+
| user_id | create_time |
+---------+---------------------+
| 100 | 2014-10-08 08:< span style="font-weight: bold;">58:58 |
| 400 | 2014-10-09 15:< span style="font-weight: bold;">34:02 |
| 600 | 2014-10-10 11:< span style="font-weight: bold;">26:10 |
+---------+---------------------+
3 rows in set (0.00 sec)
mysql> select user_id,create_time from yyfax_user.user_info where user_id in ('400',' 600','100') order by field (user_id,'400','600','100' span>);
+---------+---------------------+
| user_id | create_time |
+---------+---------------------+
| 400 | 2014-10-09 15:< span style="font-weight: bold;">34:02 |
| 600 | 2014-10-10 11:< span style="font-weight: bold;">26:10 |
| 100 | 2014-10-08 08:< span style="font-weight: bold;">58:58 |
+---------+---------------------+
3 rows in set (0.01 sec)
mysql> select user_id,tag_id from yyfax_user.user_tag where user_id='U000412280';
+------------+----------+
| user_id | tag_id |
+------------+----------+
| U000412280 | TAG20000 |
| U000412280 | TAG20002 |
| U000412280 | TAG50001 |
+------------+----------+
3 rows in set (0.00 sec)
mysql> select user_id,GROUP_CONCAT(tag_id SEPARATOR',') AS tag_id from yyfax_user.user_tag where user_id='U000412280';
+------------+----------------------------+
| user_id | tag_id |
+------------+----------------------------+
| U000412280 | TAG20000,TAG20002,TAG50001 |
+------------+----------------------------+
1 row in set (0.00 sec)
mysql> select user_id,create_time from yyfax_user.user_info where user_id in ('400','600','100 ');
+---------+---------------------+
| user_id | create_time |
+---------+---------------------+
| 100 | 2014-10-08 08:< span style="font-weight: bold;">58:58 |
| 400 | 2014-10-09 15:< span style="font-weight: bold;">34:02 |
| 600 | 2014-10-10 11:< span style="font-weight: bold;">26:10 |
+---------+---------------------+
3 rows in set (0.00 sec)
mysql> select user_id,create_time from yyfax_user.user_info where user_id in ('400','600','100 ') order by field (user_id,'400','600','100') span>;
+---------+---------------------+
| user_id | create_time |
+---------+---------------------+
| 400 | 2014-10-09 15:< span style="font-weight: bold;">34:02 |
| 600 | 2014-10-10 11:< span style="font-weight: bold;">26:10 |
| 100 | 2014-10-08 08:< span style="font-weight: bold;">58:58 |
+---------+---------------------+
3 rows in set (0.01 sec)