1.同步數據表的字段 update user u inner join user uu on u.id=uu.idset u.number1=uu.number; 2.數據表A字段的值更新到B上 update user u inner join user u uon u.id=uu.id set u.number1=(u.number1+uu.number); 3.將B表的回帖全部值更新到A表 UPDATE ultrax_forum_thread threadSET replies = (SELECT count(1) FROM ultrax_forum_post post #WHERE tid =thread.tid andwhere first=0and dateline=1425225600group by tid ) UPDATE ultrax_forum_thread thread SET replies = 1 where thread.tid in ( SELECT distinct tid FROM ultrax_forum_post post where first=0and dateline=1425225600 ) 5.查詢某個時間段的登陸天數 不能直接經過group by +count 來實現 select A.uid as uid,count(1) as login from ( select distinct from_unixtime(l.dateline,'%Y-%m-%d') as 'date', l.uid AS 'uid' from ultrax_common_member_login l where l.uid>0 and l.dateline > 1451577600 and l.dateline<1467388740 ) A group by A.uid