mysql Ò»µÀСÌâ
±íÃûΪtableµÄ±íÄÚÈÝÈçÏÂ
Year month value
2009 1 1.1
2009 2 1.2
2009 3 1.3
2009 4 1.4
2010 1 2.1
2010 2 2.2
2010 3 2.3
2010 4 2.4
ÒªÇó²éѯ½á¹ûΪ
year m1 m2 m3 m4
2009 1.1 1.2 1.3 1.4
2010 2.1 2.2 2.3 2.4
mysql> select year,sum(case when month=1 then value end) as 'm1',sum(case when m
onth=2 then value end) as 'm2',sum(case when month=3 then value end)as 'm3' from
table2 group by year;
Ïà¹ØÎĵµ£º
±¨´í£º
/tmp/ccBBJEB8.o: In function `ping_sql':
pingsql.c:(.text+0x7c): undefined reference to `mysql_init'
pingsql.c:(.text+0xe1): undefined reference to `mysql_real_connect'
pingsql.c:(.text+0xff): undefined reference to `mysql_close'
pingsql.c:(.text+0x119): undefined reference to `mys ......
mysql set names ÎÊÌâ
mysql_query("set names 'utf8'");
Ò»Ö±ÒÔÀ´×ÜÒÔΪset names ÊÇÓÃÀ´ÉèÖÃmsyql µÄ×Ö·û¼¯µÄ£¬×î½ü×÷¸ö¶«Î÷²Å·¢ÏÖ×Ô¼ºÈÏʶÉϵĴíÎó£¬
²éÒ»ÏÂÊÖ²á
SET NAMES ‘x‘Óï¾äÓëÕâÈý¸öÓï¾äµÈ¼Û£º
mysql> SET character_set_client = x;
mysql> SET character_set_results = x;
mysql> ......
¡¡¡¡
¡¡¡¡±¾ÎÄÖ÷Òª½éÉÜmysqlÊý¾Ý¿âÏÂshowÃüÁîµÄÖ÷ÒªÓ÷¨£º
¡¡¡¡a. show tables»òshow tables from database_name; -- ÏÔʾµ±Ç°Êý¾Ý¿âÖÐËùÓбíµÄÃû³Æ¡£
¡¡¡¡b. show databases; -- ÏÔʾmysqlÖÐËùÓÐÊý¾Ý¿âµÄÃû³Æ¡£
¡¡¡¡c. show columns from table_name from database_name; »òshow columns from database_name.table_n ......
Õë¶Ôselect * from table where col1 > number order by col2 desc¡£
Æäʵ°´ÕÕ³£¹æµÄ·½·¨¿ÉÒÔÕâÑùÉè¼Æ£ºkey(col1, col2)
µ«ÊÇÕâÖÖ°ì·¨ÔÚmysqlÀï²»ËãÊÇÀíÏëµÄ£¬whereÌõ¼þÀïÏÞ¶¨Ë÷Òýǰ²¿·ÖÊÇÒ»¸ö·¶Î§µÄÇé¿öϺóÃæµÄorder by»¹ÊÇ»áÓÐfilesort¡£Èç¹ûwhereÌõ¼þÀïÏÞ¶¨Ë÷Òýǰ²¿·ÖÊÇÒ»¸ö³£Á¿£¬ÄÇôorder by¾Í»áÓÐЧÀûÓÃË÷Òý¡£À ......
ǰһֱûעÒâÕâÒ»µã£¬Í»È»Ò»ÉÁÄîÏëÆðÀ´£¬ÏÂÃæßëß룺
±È·½ËµÓÐÒ»¸öÎÄÕÂ±í£¬ÎÒÃÇҪʵÏÖij¸öÀà±ðϰ´Ê±¼äµ¹ÐòÁбíÏÔʾ¹¦ÄÜ£º
SELECT * from articles WHERE category_id = … ORDER BY created DESC LIMIT …
ÕâÑùµÄ²éѯºÜ³£¼û£¬»ù±¾Éϲ»¹ÜʲôӦÓÃÀï¶¼ÄÜÕÒ³öÒ»´ó°ÑÀàËÆµÄSQLÀ´£¬Ñ§ÔºÅɵĶÁÕß¿´µ½ÉÏÃæµÄS ......