mysql 查询篇

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
相关文章
相关标签/搜索