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

mysql ʹÓÃrandËæ»ú²éѯ¼Ç¼ЧÂʲâÊÔ

Ò»Ö±ÒÔΪmysqlËæ»ú²éѯ¼¸ÌõÊý¾Ý£¬¾ÍÓÃ
SELECT
 
*
 
from
 `
table

ORDER
 
BY
 
RAND
() LIMIT 
5
¾Í¿ÉÒÔÁË¡£
µ«ÊÇÕæÕý²âÊÔһϲŷ¢ÏÖÕâÑùЧÂʷdz£µÍ¡£Ò»¸ö15ÍòÓàÌõµÄ¿â£¬²éѯ5ÌõÊý¾Ý£¬¾ÓȻҪ8ÃëÒÔÉÏ
²é¿´¹Ù·½ÊֲᣬҲ˵rand()·ÅÔÚORDER BY ×Ó¾äÖлᱻִÐжà´Î£¬×ÔȻЧÂʼ°ºÜµÍ¡£
You cannot use a column with RAND() values in an ORDER BY clause,
because ORDER BY would evaluate the column multiple times.
ËÑË÷Google£¬ÍøÉÏ»ù±¾É϶¼ÊDzéѯmax(id) * rand()À´Ëæ»ú»ñÈ¡Êý¾Ý¡£
SELECT
 
*
 
from
 `
table

AS
 t1 
JOIN
 (
SELECT
 
ROUND
(
RAND
() 
*
 (
SELECT
 
MAX
(id) 
from
 `
table
`)) 
AS
 id) 
AS
 t2 
WHERE
 t1.id 
>=
 t2.id 
ORDER
 
BY
 t1.id 
ASC
 LIMIT 
5
;
µ«ÊÇÕâÑù»á²úÉúÁ¬ÐøµÄ5Ìõ¼Ç¼¡£½â¾ö°ì·¨Ö»ÄÜÊÇÿ´Î²éѯһÌõ£¬²éѯ5´Î¡£¼´±ãÈç´ËÒ²ÖµµÃ£¬ÒòΪ15ÍòÌõµÄ±í£¬²éѯֻÐèÒª0.01Ãë²»µ½¡£
ÉÏÃæµÄÓï¾ä²ÉÓõÄÊÇJOIN£¬mysqlµÄÂÛ̳ÉÏÓÐÈËʹÓÃ
SELECT
 
*
 
from
 `
table

WHERE
 id 
>=
 (
SELECT
 
FLOOR

MAX
(id) 
*
 
RAND
()) 
from
 `
table
` ) 
ORDER
 
BY
 id LIMIT 
1
;
ÎÒ²âÊÔÁËһϣ¬ÐèÒª0.5Ã룬ËÙ¶ÈÒ²²»´í£¬µ«ÊǸúÉÏÃæµÄÓï¾ä»¹ÊÇÓкܴó²î¾à¡£×ܾõÓÐʲôµØ·½²»Õý³£¡£
ÓÚÊÇÎÒ°ÑÓï¾ä¸ÄдÁËһϡ£
SELECT
 
*
 
from
 `
table

WHERE
 id 
>=
 (
SELECT
 
floor
(
RAND
() 
*
 (
SELECT
 
MAX
(id) 
from
 `
table
`)))  
ORDER
 
BY
 id LIMIT 
1
;
ÕâÏ£¬Ð§ÂÊÓÖÌá¸ßÁË£¬²éѯʱ¼äÖ»ÓÐ0.01Ãë
×îºó£¬ÔÙ°ÑÓï¾äÍêÉÆһϣ¬¼ÓÉÏMIN(id)µÄÅжϡ£ÎÒÔÚ×ʼ²âÊÔµÄʱºò£¬¾ÍÊÇÒòΪûÓмÓÉÏMIN(id)µÄÅжϣ¬½á¹ûÓÐÒ»°ëµÄʱ¼ä×ÜÊDzéѯµ½±í
ÖеÄÇ°Ã漸ÐС£
ÍêÕû²éѯÓï¾äÊÇ£º
SELECT
 
*
 
from
 `
table

WHERE
 id 
&g


Ïà¹ØÎĵµ£º

MySQL³£ÓÃÃüÁî×ܽá

MySQL³£ÓÃÃüÁî×ܽá
===MySQL»ù´¡====
mysqlÏÂÔØ: http://www.mysql.com/
mysqld ³£¹æMySQL·þÎñÆ÷
mysqld-opt ÓÅ»¯mysql·þÎñÆ÷,ÌṩһЩ¹¦ÄÜ¿ÉÒÔÍÚ¾ò¸üºÃµÄ¹¦ÄÜ
mysqld-max ÓëmysqldÒ»Ñù,µ«¿ÉÒÔÖ§³Ö¸üÐÂ,¸ü¾ßʵÑéÐÔÖʵŦÄÜ(¸ü²»Îȶ¨)
++°²×°mysql
²Î¼û×Ô´øµÄINSTALL-SOURCEÎļþ
$ ./configure –prefix=/app/m ......

OracleºÍMySQLÊý¾Ý¿âµÄһЩ¼òµ¥ÃüÁî¶Ô±È

ÒÔÏÂΪOracleºÍMySQLÊý¾Ý¿âµÄһЩ¼òµ¥ÃüÁî¶Ô±È£¬¿´¿´ËüÃÇÖ®¼ä´æÔÚÄÄЩ²îÒì
¡¡¡¡SQL> select to_char(sysdate,'yyyy-mm-dd') from dual;
¡¡¡¡SQL> select to_char(sysdate,'hh24-mi-ss') from dual;
¡¡¡¡mysql> select date_format(now(),'%Y-%m-%d');
¡¡¡¡mysql> select time_format(now(),'%H-%i-%S');
¡¡¡¡ÈÕÆÚº ......

MySqlÃüÁî´óÈ«

1. Á¬½Ómysql:
mysqlbinmysql -hÖ÷»úµØÖ· -u Óû§Ãû £­p Óû§ÃÜÂë
2.Í˳ömysql:exit
3. ÐÞ¸ÄÃÜÂë:
mysqlbinmysqladmin -uroot -p(oldpassword) password newpassword
4.Ôö¼ÓÓû§£º
Ìí¼ÓÒ»¸öÓû§test1 ÃÜÂëΪABC£»ÈÃËû¿ÉÒÔÔÚÈκÎÖ÷»úÉϵǼ,²¢¶ÔËùÓÐÊý¾Ý¿âÓвéѯ¡¢²åÈë¡¢Ð޸ġ¢É¾³ýµÄȨÏÞ¡£Ê×ÏÈÓÃÒÔrootÓû§Á¬Èë
mysq ......

Linux Ô´Âë°²×°Mysql5.5

¹«Ë¾µÄ·þÎñÆ÷ÊÇCentOS 5.4(Final)°æµÄ£¬½ñÌìÔÚÉÏÃæ°²×°ÁËÒ»»Ømysql5.5£¬¼Ç¼ÈçÏ£º
1¡¢´Óhttp://blog.s135.com/soft/linux/nginx_php/mysql/mysql-5.5.2-m2.tar.gz ÏÂÔØÔ´Âë°²×°°üµ½/usr/local/src
2¡¢tar zxvf mysql-5.5.2-m2.tar.gz ½âѹµ½/usr/local/src/mysql-5.5.2-m2ÏÂ
    cd mysql-5.5.2-m2/
&n ......

MySQL Á·Ï°ÊÖ¸å

MySQL Á·Ï°ÊÖ¸å
      MySQL ½éÉÜ
      MySQL ABÊÇÓÉMySQL´´Ê¼È˺ÍÖ÷Òª¿ª·¢ÈË´´°ìµÄ¹«Ë¾¡£MySQL AB×î³õÊÇÓÉDavid Axmark¡¢Allan
LarssonºÍMichael“Monty
”WideniusÔÚÈðµä´´°ìµÄ¡£
      ¹«Ë¾ÃûÖеēAB”ÊÇÈðµäÓ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ