开发者

SELECT USING COUNT in mysql

开发者 https://www.devze.com 2022-12-29 15:00 出处:网络
I have a very large database with about 120 Million records in one table.I have clean up the data in this table first before I divide it into several tables(possibly normalizing it). The columns of th

I have a very large database with about 120 Million records in one table.I have clean up the data in this table first before I divide it into several tables(possibly normalizing it). The columns of this table is as follows: "id(Primary Key), userId, Url, Tag " . This is basically a subset of the dataset from delicious website. As I said, each row has an id, userID a url and only "one" tag. So for example a bookmark in delicious website is composed of several tags for a single url, this corresponds to several lines of my database. for example:

"id"; "user" ;"url" ;"tag" 
"38";"12c2763095ec44e498f870ed67ee948d";"http://forkjavascript.org/";"ajax" 
"39";"12c2763095ec44e498f870ed67ee948d";"http://forkjavascript.org/";"api" 
"40";"12c2763095ec44e498f870ed67ee948d";"http://forkjavascript.org/";"javascript" 
"41";"12c2763095ec44e498f870ed开发者_开发知识库67ee948d";"http://forkjavascript.org/";"library" 
"42";"12c2763095ec44e498f870ed67ee948d";"http://forkjavascript.org/";"rails"

I need a query to count the number of times that a tag is used for a url. Thank you for you help


This query should work for you:

SELECT tag, url, count(tag) FROM table GROUP BY tag, url

Haven't tested it for you though.


Is this what you are looking for?

SELECT COUNT(tag) FROM TABLENAME
WHERE tag='sometag'


I think it's actually more like SELECT tag, COUNT(tag) FROM TABLENAME WHERE URL='someurl' GROUP BY tag

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号