首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在大型MySQL数据库中查找最常用的单词

在大型MySQL数据库中查找最常用的单词
EN

Stack Overflow用户
提问于 2017-05-17 21:49:23
回答 2查看 2.5K关注 0票数 2

我有一个旧的MySQL数据库,它的单列中包含超过4,000,000行。每一行都包含一个业务名称,当然,其中许多名称包含多个单词。

我想找出这个数据库中最常用的前1000个单词。是否可以使用MySQL查询?

EN

回答 2

Stack Overflow用户

发布于 2017-05-17 22:20:37

考虑下面的例子...

代码语言:javascript
复制
CREATE TABLE soliloquy
(line_number INT NOT NULL AUTO_INCREMENT PRIMARY KEY
,line VARCHAR(255) NOT NULL
);

INSERT INTO soliloquy (line) VALUES
("To be, or not to be, that is the question:"),
("Whether 'tis nobler in the mind to suffer"),
("The slings and arrows of outrageous fortune,"),
("Or to take Arms against a Sea of troubles,"),
("And by opposing end them: to die, to sleep"),
("No more; and by a sleep, to say we end"),
("the heart-ache, and the thousand natural shocks"),
("that Flesh is heir to? 'Tis a consummation"),
("devoutly to be wished. To die, to sleep,"),
("To sleep, perchance to Dream; aye, there's the rub,"),
("for in that sleep of death, what dreams may come,"),
("when we have shuffled off this mortal coil,"),
("must give us pause. There's the respect"),
("that makes Calamity of so long life:"),
("For who would bear the Whips and Scorns of time,"),
("the Oppressor's wrong, the proud man's Contumely,"),
("the pangs of despised Love, the Law’s delay,"),
("the insolence of Office, and the spurns"),
("that patient merit of the unworthy takes,"),
("when he himself might his Quietus make"),
("with a bare Bodkin? Who would Fardels bear,"),
("to grunt and sweat under a weary life,"),
("but that the dread of something after death,"),
("the undiscovered country, from whose bourn"),
("no traveller returns, puzzles the will,"),
("and makes us rather bear those ills we have,"),
("than fly to others that we know not of."),
("Thus conscience does make cowards of us all,"),
("and thus the native hue of Resolution"),
("Is sicklied o'er, with the pale cast of Thought,"),
("And enterprises of great pitch and moment,"),
("with this regard their Currents turn awry,"),
("And lose the name of Action. Soft you now,"),
("The fair Ophelia? Nymph, in thy Orisons"),
("Be all my sins remember'd");

下面是每个单词在多少行内出现的计数-与每个单词出现的频率略有不同...

哦,还有int只是一个整数表i...

代码语言:javascript
复制
SELECT word
     , COUNT(*) total
  FROM 
     ( SELECT DISTINCT line_number
                     , SUBSTRING_INDEX(SUBSTRING_INDEX(line,' ',i+1),' ',-1) word
                  FROM soliloquy
                     , ints 
     ) x
 GROUP
    BY word
HAVING COUNT(*) > 3 
 ORDER
    BY total DESC
     , word;

+------+-------+
| word | total |
+------+-------+
| the  |    18 |
| of   |    14 |
| and  |    11 |
| To   |     9 |
| that |     7 |
| a    |     5 |
| we   |     4 |
+------+-------+

哦,在标点符号方面可能有一些小错误-但你应该明白这一点。

票数 2
EN

Stack Overflow用户

发布于 2018-01-16 22:48:56

草莓答案的变体,在公司网站管理面板上工作和使用。

代码语言:javascript
复制
<?php
global $con;
$i = 1;

echo "Most Popular Searches";
$select = "select *, COUNT(*) total from mytable group by mytablecolumn having count(*) > 3 order by total desc";

$connect = mysqli_query($con, $select);
while($row=mysqli_fetch_array($connect)) {
$words = $row['mytablecolumn'];
echo "$i: $words<br/>";
$i++;
}
?>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44026794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档