MysqlµÄGROUP_CONCAT()º¯ÊýʹÓ÷½·¨ ¶àÐкϲ¢º¯Êý
GROUP_CONCAT ÊÇÒ»¸öºÏ²¢¶àÐеĺ¯Êý£¬Ò»°ãÓõÄÉÙ£¬ËùÒԺܶàÈ˶¼²»ÖªµÀ£¬ÎÒÒ²ÊÇÒ»¸ö£¬½ñÌìżȻ¿´µ½£¬¹Ê¼ÇÏ·½·¨£»
GROUP_CONCATµÄÓï·¨ÈçÏ£º
GROUP_CONCAT([DISTINCT] expr [,expr ...][ORDER BY {unsigned_integer | col_name | expr}[ASC | DESC] [,col_name ...]][SEPARATOR str_val])
ÏÂÃæÑÝʾһÏÂÕâ¸öº¯Êý£¬ÏȽ¨Á¢Ò»¸öѧÉúÑ¡¿Î±ístudent_courses£¬²¢Ìî³äһЩ²âÊÔÊý¾Ý¡£
SQL´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
CREATE TABLE student_courses (
student_id INT UNSIGNED NOT NULL,
courses_id INT UNSIGNED NOT NULL,
KEY(student_id)
);
INSERT INTO student_courses VALUES (1, 1), (1, 2), (2, 3), (2, 4), (2, 5);
ÈôÒª²éÕÒѧÉúIDΪ2ËùÑ¡µÄ¿Î³Ì£¬ÔòʹÓÃÏÂÃæÕâÌõSQL£º
SQL´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
mysql> SELECT student_id, courses_id from student_courses WHERE student_id=2;
+------------+------------+
| student_id | courses_id |
+------------+------------+
| 2 | 3 |
| 2 | 4 |
| 2 | 5 |
+------------+------------+
3 rows IN SET (0.00 sec)
Êä³ö½á¹ûÓÐ3Ìõ¼Ç¼£¬ËµÃ÷ѧÉúIDΪ2µÄѧÉúÑ¡ÁË3¡¢4¡¢5Õâ3Ãſγ̡£
·ÅÔÚPHPÀ±ØÐëÓÃÒ»¸öÑ»·²ÅÄÜÈ¡µ½Õâ3Ìõ¼Ç¼£¬ÈçÏÂËùʾ£º
PHP´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
foreach ($pdo->query("SELECT student_id, courses_id from student_courses WHERE student_id=2") as $row) {
$result[] = $row['courses_id'];
}
¶øÈç¹û²ÉÓÃGROUP_CONCAT()º¯ÊýºÍGROUP BYÓï¾ä¾ÍÏԵ÷dz£¼òµ¥ÁË£¬ÈçÏÂËùʾ£º
SQL´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
mysql> SELECT student_id, GROUP_CONCAT(courses_id) AS courses from student_courses WHERE student_id=2 GROUP BY student_id;
+------------+---------+
| student_id | courses |
+------------+---------+
| 2 | 3,4,5 |
+------------+---------+
1 row IN SET (0.00 sec)
ÕâÑùphpÀï´¦Àí¾Í¼òµ¥ÁË£º
PHP´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
$row = $pdo->query("SELECT student_id, GROUP_CONCAT(courses_id) AS courses from student_courses WHERE student_id=2 GROUP BY student_id");
$result = explode(',', $row['courses']);
·Ö¸ô·û»¹¿ÉÒÔ×Ô¶¨Ò壬ĬÈÏÊÇÒÔ“,”×÷Ϊ·Ö¸ô·û£¬ÈôÒª¸ÄΪ“|||”£¬ÔòʹÓÃSEPARATORÀ´Ö¸¶¨£¬ÀýÈ磺
SQL´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
Ïà¹ØÎĵµ£º
ÔÚÌÚ¿ÆÅàѵÁËÓÐ1¸ö°ëÔÂÁË£¬ÖÕÓÚѧÍêJSP+SERVLET+JAVABEAN+MYSQL£¬Ñ§ÁËjavaµÄµÚÒ»Ì×web½â¾ö·½°¸¡£ÀÏʦҪÇóÎÒÃÇ6ÈËÒ»×鿪ʼ×öÒ»¸ö¶©²Íϵͳ¡£Õâ¸öϵͳûÓÐÊ²Ã´ÌØ±ðµÄ£¬¾Í¸úµç×ÓÉ̳ÇÊÇÒ»¸öÑùµÄ¡£ÓÉÓÚÒª¶ÔÊý¾Ý¿â×ö´óÁ¿µÄÔöɾ¸Ä²é£¬ÄǸö´úÂëÓֶ࣬ÎÒÏëÄܲ»Äܽ«Êý¾Ý¿â²Ù×÷µÄÕâÒ»²ã´ò°üÆðÀ´(SqlOperDao)£¬ÈÃÎÒ¶ÔÊý¾Ý¿â²Ù×÷£¬Óü¸Ðд ......
mysqld³ÌÐò--Ŀ¼ºÍÎļþ
basedir = path ʹÓøø¶¨Ä¿Â¼×÷Ϊ¸ùĿ¼(°²×°Ä¿Â¼)¡£
character-sets-dir = path ¸ø³ö´æ·Å×Å×Ö·û¼¯µÄĿ¼¡£
datadir = path ´Ó¸ø¶¨Ä¿Â¼¶ÁÈ¡Êý¾Ý¿âÎļþ¡£
pid-file = filename Ϊmysqld³ÌÐòÖ¸¶¨Ò»¸ö´æ·Å½ø³ÌIDµÄÎļþ(½öÊÊÓÃÓÚUNIX/Linuxϵͳ); Init-V½Å±¾ÐèҪʹÓÃÕâ¸öÎļþÀïµÄ½ø³ÌID½áÊømysqld½ø ......
Ðè×¢ÒâÒÔÏÂÈýµã£º
1¡¢´´½¨Êý¾Ý¿âµÄʱºò£ºCREATE DATABASE `database`
CHARACTER SET 'utf8'
  ......
°Ñmysql.h¸´ÖƵ½vcµÄĿ¼µÄincludeĿ¼ÏÂ
mysql.hÔÚÄãmysqlµÄ°²×°Ä¿Â¼ÏµÄincludeÀïÃæÈç:mysql\include
°Ñlibmysql.lib(ÔÚmysqlµÄ°²×°Ä¿Â¼Ï£¬ËÑË÷ϾÍÄÜÕÒµ½£©¸´ÖƵ½Õâ¸öĿ¼Ï£¨C:\Program Files\Microsoft Visual Studio 9.0\VC\lib£©£¬Òª²»Á¬½Ó»á³ö´í¡£
Èç¹û±àÒëÁ¬½Óʱ»¹Êdzö´í¡£¾Í°Ñlibmysql.lib¸´ÖƵ½ÄãÔ´³ÌÐòµÄÄ¿ ......
Starting the cluster is not very difficult after it has been configured. Each cluster node process must be started separately, and on the host where it resides. The management node should be started first, followed by the data nodes, and then finally by any SQL nodes:
On the management host, issu ......