最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL中g(shù)roup_concat函數(shù)深入理解

 更新時間:2012年11月14日 16:28:43   作者:  
本文通過實例介紹了MySQL中的group_concat函數(shù)的使用方法,需要的朋友可以適當(dāng)參考下
本文通過實例介紹了MySQL中的group_concat函數(shù)的使用方法,比如select group_concat(name) 。
MySQL中g(shù)roup_concat函數(shù)
完整的語法如下:
group_concat([DISTINCT] 要連接的字段 [Order BY ASC/DESC 排序字段] [Separator '分隔符'])
基本查詢
mysql> select * from aa;
+------+------+
| id| name |
+------+------+
|1 | 10|
|1 | 20|
|1 | 20|
|2 | 20|
|3 | 200 |
|3 | 500 |
+------+------+
6 rows in set (0.00 sec)
以id分組,把name字段的值打印在一行,逗號分隔(默認(rèn))
mysql> select id,group_concat(name) from aa group by id;
+------+--------------------+
| id| group_concat(name) |
+------+--------------------+
|1 | 10,20,20|
|2 | 20 |
|3 | 200,500|
+------+--------------------+
3 rows in set (0.00 sec)
以id分組,把name字段的值打印在一行,分號分隔
mysql> select id,group_concat(name separator ';') from aa group by id;
+------+----------------------------------+
| id| group_concat(name separator ';') |
+------+----------------------------------+
|1 | 10;20;20 |
|2 | 20|
|3 | 200;500 |
+------+----------------------------------+
3 rows in set (0.00 sec)
以id分組,把去冗余的name字段的值打印在一行,
逗號分隔
mysql> select id,group_concat(distinct name) from aa group by id;
+------+-----------------------------+
| id| group_concat(distinct name) |
+------+-----------------------------+
|1 | 10,20|
|2 | 20 |
|3 | 200,500 |
+------+-----------------------------+
3 rows in set (0.00 sec)
以id分組,把name字段的值打印在一行,逗號分隔,以name排倒序
mysql> select id,group_concat(name order by name desc) from aa group by id;
+------+---------------------------------------+
| id| group_concat(name order by name desc) |
+------+---------------------------------------+
|1 | 20,20,10 |
|2 | 20|
|3 | 500,200|
+------+---------------------------------------+
3 rows in set (0.00 sec)
使用group_concat_max_len系統(tǒng)變量,你可以設(shè)置允許的最大長度。 程序中進(jìn)行這項操作的語法如下,其中 val 是一個無符號整數(shù):
SET [SESSION | GLOBAL] group_concat_max_len = val;
若已經(jīng)設(shè)置了最大長度, 則結(jié)果被截至這個最大長度。
將環(huán)境變量group_concat_max_len 增大。默認(rèn)是1024.我就設(shè)置了session級的環(huán)境變量將其變?yōu)?048(不夠用再加大)。解決該問題

相關(guān)文章

最新評論

衡南县| 库尔勒市| 蒙自县| 纳雍县| 清徐县| 盖州市| 平和县| 株洲县| 烟台市| 南康市| 巴东县| 长乐市| 富阳市| 新沂市| 绥中县| 库尔勒市| 攀枝花市| 垦利县| 兰坪| 乡城县| 滨海县| 额济纳旗| 贵定县| 胶州市| 阿合奇县| 麻城市| 满城县| 囊谦县| 永定县| 交口县| 项城市| 丘北县| 新巴尔虎左旗| 土默特左旗| 马龙县| 敦化市| 仪陇县| 邢台县| 方城县| 华宁县| 石河子市|