您的位置:首页 > 数据库 > MySQL

mysql一些实用的语句

2016-04-25 09:52 495 查看
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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: