mysql一些实用的语句

来源:互联网 发布:犀牛o2o源码 编辑:程序博客网 时间:2024/05/21 06:53

1、计算不重复的数据
select count(distinct(userID)) from relationship;

2、计算相同的数据
select count(1) from relationship group by userID;

3、对同一个表进行查询和删除

delete from relationship where userID in (select * from(select userID from relationship group by userID having count(1)<10)w);

4、根据查询出的结果更新表的内容
UPDATE dataall INNER JOIN user ON dataall.userID=user.userID SET dataall.hash_userID=user.hash_userID;

5、将查询出的内容写入到文件中
select hash_userID,hash_bookmarkID,hash_tagID from dataall WHERE NO%4!=0 into outfile ‘D:\dataall201010base1.txt’;

6、根据查询结果插入表中
insert into tag (tagID) select distinct(tagID) from dataall;

7、按照分组,找出每组中前几条数据,并写入文件
select a.*
from 201010base11 a
where ( select count(1)
from 201010base11
where userID=a.userID and score > a.score ) <2
order by a.userID,a.score desc into outfile ‘D:\Topn.txt’;

8、计算一个表中,与另一个表的重复数据
select count(1) from topn a,(select userID,bookmarkID,tagID from 201010test1)b where a.userID=b.userID AND a.bookmarkID=b.bookmarkID AND a.tagID= b.tagID;

1 0
原创粉丝点击