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´úÂë
¸´ÖÆ´úÂë ´úÂëÈçÏÂ:
Ïà¹ØÎĵµ£º
#Á½ÈÕÆÚ/ʱ¼äÖ®¼äÏà²îµÄÌìÊý£º¡¡
To_Days(end_time)-To_Days(start_time)¡¡
#Á½ÈÕÆÚ/ʱ¼äÖ®¼äÏà²îµÄÃëÊý£º¡¡
SELECT¡¡UNIX_TIMESTAMP(end_time)-¡¡UNIX_TIMESTAMP(start_time);¡¡
#Á½ÈÕÆÚ/ʱ¼äÖ®¼äÏà²îµÄʱ·ÖÊý£º¡¡
SELECT¡¡SEC_TO_TIME(UNIX_TIMESTAMP(end_time)-¡¡UNIX_T ......
Love in coding...
Free and Susan
[Òý]MySQL INNODBÀàÐͱíµÄÍâ¼ü¹ØÁªÉèÖÃ
Here is a simple example that relates parent and child tables through a single-column foreign key:
CREATE TABLE parent (id INT NOT NULL,
......
MySQL·þÎñÆ÷²ÉÓÃÁËÄ£¿é»¯·ç¸ñ£¬¸÷²¿·ÖÖ®¼ä±£³ÖÏà¶Ô¶ÀÁ¢£¬ÓÈÆäÌåÏÖÔÚ´æ´¢¼Ü¹¹ÉÏ¡£´æ´¢ÒýÇæ¸ºÔð
¹ÜÀíÊý¾Ý´æ´¢£¬ÒÔ¼°MySQLµÄË÷Òý¹ÜÀí¡£Í¨¹ý¶¨ÒåµÄAPI£¬MySQL·þÎñÆ÷Äܹ»Óë´æ´¢ÒýÇæ½øÐÐͨÐÅ¡£Ä¿Ç°Ê¹ÓÃ×î¶àµÄÊÇMyISAMºÍInnoDB¡£
InnoDB±»OracleÊÕ¹ººó£¬MySQL×ÔÐпª·¢µÄд洢ÒýÇæFalcon½«ÔÚMySQL6.0°æ±¾Òý½ø¡£
MyISAMÒýÇæÊÇÒ ......
°Ñ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 ......