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´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
Ïà¹ØÎĵµ£º
ÔËÐл·¾³£ºwindows xp sp2
IIS v5.1
PHP 5.3.1-Win32-VC9-x86
Mysql 5.0
°²×°²½Ö裺
°²×°IIS5.1
ÔÚ ......
Æô¶¯Mysql ´íÎó 1067 ½ø³ÌÒâÍâÖÕÖ¹µÄÒ»ÖÖ½â¾ö·½·¨
mysqld-nt --defaults-file=my.ini --standalone --console
²é¿´ÐÅÏ¢ÄÚÈÝ
·¢ÏÖMYSQL INNODB³õʼ»¯´íÎó¡£
´íÎóÈçÏ£º
InnoDB: The first specified data file .\ibdata1 did not exist:
InnoDB: a new database to be created!
100115 10:14:04 InnoDB: Setti ......
Ê×ÏÈÒªÉùÃ÷Ò»µã£¬´ó²¿·ÖÇé¿öÏ£¬ÐÞ¸ÄMySQLÊÇÐèÒªÓÐmysqlÀïµÄrootȨÏ޵ģ¬
ËùÒÔÒ»°ãÓû§ÎÞ·¨¸ü¸ÄÃÜÂ룬³ý·ÇÇëÇó¹ÜÀíÔ±¡£
·½·¨Ò»
ʹÓÃphpmyadmin£¬ÕâÊÇ×î¼òµ¥µÄÁË£¬ÐÞ¸Ämysql¿âµÄuser±í£¬
²»¹ý±ðÍüÁËʹÓÃPASSWORDº¯Êý¡£
·½·¨¶þ
ʹÓÃmysqladmin£¬ÕâÊÇÇ°ÃæÉùÃ÷µÄÒ»¸öÌØÀý¡£
mysqladmin -u root -p password mypas ......
ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«Ñ§Ï°ÈçºÎͨ¹ýPHP 5µÄÒ»¸ö»ù±¾³éÏóÀàʹÓÃÍâ¼üÔ¼ÊøÀ´¸üÐÂÁ½¸öInnoDB±íµÄÊý¾Ý¡£ ÎÒÃǽ«Í¨¹ý¾ßÌåʾÀýÀ´ËµÃ÷ÈçºÎͨ¹ý·þÎñÆ÷¶Ë½Å±¾ÓïÑÔÀ´Ê¹ÓÃÍâ¼üÔ¼Êø¡£
¡¡¡¡Ò»¡¢ÀûÓÃÍâ¼üÔ¼Êø¸üÐÂMySQLÖеÄÊý¾Ý
¡¡¡¡ÏÖÔÚ£¬×îÁ÷ÐеĿªÔ´¹ØÏµÐÍÊý¾Ý¿â¹ÜÀíϵͳ·ÇMySQLĪÊô£¬¶øMySQLÓÖÖ§³Ö¶à¸ö´æ´¢ÒýÇæ£¬ÆäÖÐĬÈϵÄÒ²ÊÇËٶȽϿìµÄ´ ......
To shut down the cluster, enter the following command in a shell
on the machine hosting the management node:
shell> ndb_mgm -e shutdown
The -e
option here is used to pass a command to
the ndb_mgm
client from the shell. (See
Section 4.23, “ ......