dpbz14739 2017-06-10 00:23
浏览 12
已采纳

Mysql查询:查找最少使用的单词

I have a table of words used in the title of articles. I want to find which words which are used the least in the set or article titles.

Example:

Titles:

"Congressman Joey of Texas does not sign bill C1234."
"The pretty blue bird flies at night in Texas."
"Congressman Bob of Arizona is the signs bill C1234."

The table would contain the following.

Table WORDS_LIST

----------------------------------------------------
| INDEX ID | WORD                     | ARTICLE ID |
----------------------------------------------------
| 1        | CONGRESSMAN              | 1234       |
| 2        | JOEY                     | 1234       |
| 3        | SIGN                     | 1234       |
| 4        | BILL                     | 1234       |
| 5        | C1234                    | 1234       |    
| 6        | TEXAS                    | 1234       |
| 7        | PRETTY                   | 1235       |
| 8        | BLUE                     | 1245       |
| 9        | BIRD                     | 1245       |
| 10       | FLIES                    | 1245       |
| 11       | NIGHT                    | 1245       |
| 12       | TEXAS                    | 1245       |
| 13       | CONGRESSMAN              | 1246       |
| 14       | BOB                      | 1246       |
| 15       | ARIZONA                  | 1246       |
| 16       | SIGNS                    | 1246       |
| 17       | BILL                     | 1246       |
| 18       | C1234                    | 1246       |
----------------------------------------------------

In this case, the words "pretty,blue, flies, night" would be the used in the least number of articles.

I would appreciate any ideas on how to best create this query. So far below is what I started with. I can also write something in PHP but figured a query would be faster.

SELECT distinct a1.`word`, count(a1.`word`)
FROM mmdb.words_list a1
JOIN mmdb.words_list b1 
ON a1.id = b1.id AND
upper(a1.word) = upper(b1.word)
where date(a1.`publish_date`) = '2017-06-09'
group by `word`
order by count(a1.`word`);
  • 写回答

2条回答 默认 最新

  • duangouyan3328 2017-06-10 00:28
    关注

    Try this. It's a bit more simple and should return the correct results:

    SELECT `WORD`,
        COUNT(*) as `num_articles`
    FROM `WORDS_LIST`
    WHERE date(`publish_date`) = '2017-06-09'
    GROUP BY `WORD`
    ORDER BY COUNT(*) ASC;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题