Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

mysql distinct ¶Ô¶à×ֶιýÂ˲»ÕýÈ·µÄ½â¾ö·½·¨


ÏÂÃæÏÈÀ´¿´¿´Àý×Ó£º
    table
  id name
  1 a
  2 b
  3 c
  4 c
  5 b
¿â½á¹¹´ó¸ÅÕâÑù£¬ÕâÖ»ÊÇÒ»¸ö¼òµ¥µÄÀý×Ó£¬Êµ¼ÊÇé¿ö»á¸´Ôӵöࡣ
±ÈÈçÎÒÏëÓÃÒ»ÌõÓï¾ä²éѯµÃµ½name²»Öظ´µÄËùÓÐÊý¾Ý£¬ÄǾͱØÐëʹÓÃdistinctÈ¥µô¶àÓàµÄÖظ´¼Ç¼¡£
select distinct name from table
µÃµ½µÄ½á¹ûÊÇ:
  name
  a
  b
  c
ºÃÏñ´ïµ½Ð§¹ûÁË£¬¿ÉÊÇ£¬ÎÒÏëÒªµÃµ½µÄÊÇidÖµÄØ£¿¸ÄһϲéѯÓï¾ä°É:
select distinct name, id from table
½á¹û»áÊÇ:
  id name
  1 a
  2 b
  3 c
  4 c
  5 b
distinctÔõôûÆð×÷Óã¿×÷ÓÃÊÇÆðÁ˵ģ¬²»¹ýËûͬʱ×÷ÓÃÁËÁ½¸ö×ֶΣ¬Ò²¾ÍÊDZØÐëµÃidÓëname¶¼ÏàͬµÄ²Å»á±»Åųý¡£¡£¡£¡£¡£¡£¡£
½â¾ö·½·¨: select id, name from table group by name
¹þ¹þ£¡ÇëÊÊÓ¦MYSQLµÄд·¨°É


Ïà¹ØÎĵµ£º

mysql Óï¾äÓÅ»¯²éѯ

ÎÒÓõÄÊÇmysql5.0£¬
ÎÒ³ÌÐòÖÐÓõ½ÁËÒ»¾äsqlÊÇ
SQL code
select count(DISTINCT id) from Policyinfo p where p.filename not in
(select p2.filename from Policyreadinfo p2 where p2.reader='test')
µ«ÊÇÿ´ÎÔÚ³ÌÐòÖÐÿ´ÎÖ´ÐÐÕâ¾äsqlʱÍøÒ³¾ÍÌØÂý£¬Òª10¶àÃ룬¶øÕâ2¸ö±íµÄ¼Ç¼ÐÐÊýÒ²¾Í1000¶à¶øÒÑ£¬ÎÒ°ÑÕâ¾äsqlµ¥¶ÀÄ ......

Mysql°²×°

windows주
½â¾ö°ì·¨£º
1.¼ì²éÄãµÄMysqlĿ¼ÓÐûÓиøϵͳµÄSystemÓû§È¨ÏÞ¡£
2.ɾ³ýµôÄãµÄ %WINDOWS%/my.ini Îļþ¡£
3.¼ì²éÄãµÄ c:/my.cnf ÎļþÅäÖÃÊÇ·ñÕýÈ·¡£ 
ÐÞ¸Ä%windir%\my.ini£¬Ôö¼Ó
[mysqld]
#ÉèÖÃbasedirÖ¸ÏòmysqlµÄ°²×°Â·¾¶
basedir=D:\Program\Tools\mysql
datadir=D:\Program\Tools\mysql\data& ......

MySQLÈçºÎÀûÓÃË÷ÒýÓÅ»¯ORDER BYÅÅÐòÓï¾ä


MySQLË÷Òýͨ³£ÊDZ»ÓÃÓÚÌá¸ßWHEREÌõ¼þµÄÊý¾ÝÐÐÆ¥Åä»òÕßÖ´ÐÐÁª½á²Ù×÷ʱƥÅäÆäËü±íµÄÊý¾ÝÐеÄËÑË÷Ëٶȡ£
MySQLÒ²ÄÜÀûÓÃË÷ÒýÀ´¿ìËÙµØÖ´ÐÐORDER BYºÍGROUP BYÓï¾äµÄÅÅÐòºÍ·Ö×é²Ù×÷¡£
ͨ¹ýË÷ÒýÓÅ»¯À´ÊµÏÖMySQLµÄORDER BYÓï¾äÓÅ»¯£º
1¡¢ORDER BYµÄË÷ÒýÓÅ»¯¡£Èç¹ûÒ»¸öSQLÓï¾äÐÎÈ磺
SELECT [column1],[column2],…. fro ......

¸ßÐÔÄÜMySqlѧϰ±Ê¼Ç(Ò»)

¸ßÐÔÄÜMySqlѧϰ±Ê¼Ç
1.Õë¶ÔÓ¦Óý¨Á¢×Ô¼ºµÄË÷Òý
URL²éÕÒÀý×Ó
    select * from tUrl where url='http://www.163.com';
ÒÔurl£¨×Ö·û´®£©×÷ÐÐΪË÷Òý»áʹµÃ×÷ΪË÷Òý½á¹¹µÄB-Tree±ä´ó£¬¿ÉÒÔÒƳýurlÁÐÉϵÄË÷Òý£¬²¢Ìí¼ÓÒ»¸öurl_crcË÷ÒýÁУ¬
ÏȽ¨Á¢±í£º
create tables tUrl(
     ......

MySQLÊý¾Ý¿âÉè¼ÆÔ­Ôò

ת×Ô http://www.supidea.com/post/mysql_design_database.aspx
MySQLÊý¾Ý¿âÉè¼ÆÔ­Ôò
MySQL¶ÔÓÚ³ÉΪһ¸ö·Ç³£¿ìËÙµÄÊý¾Ý¿â·þÎñÆ÷ÓÐ×ŵ±Ö®ÎÞÀ¢µÄÃûÉù£¬ËüÒ²·Ç³£ÈÝÒ×ÉèÖúÍʹÓá£Ëæ×ÅËü×÷ΪÍøÕ¾ºó¶ËÊý¾Ý¿âµÃÉùÍûÈÕÔö£¬ÆäЧ¹ûÔÚÈ¥Ä꿪ʼÓÐÃ÷ ÏÔÌá¸ß¡£µ«ÊǺܶàMySQLÓû§¸ü¶àµØÖªµÀÈçºÎ´´½¨Ò»¸öÊý¾Ý¿â²¢±àд¶ÔËüµÄ²éѯ¡£¾ÍÏñ³ÉÇ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ