首页 > 解决方案 > 试图找到所有hastag计数并在MYSQL DB中插入一个数量

问题描述

我使用 PHP 和 MYSQL 数据库。

好的,所以我有 2 张桌子,一张被称为discover_section,另一张被称为videos。我想videosdiscover_section.

例如,#plantAtree hastags 的数量在该video部分中出现了 20 次。现在我想在discover_section列中设置该金额。然后转到discover_section(#test)中找到的下一个标签并查看在video表中找到的次数等。

我该怎么做呢?

我的表如下所示:

发现部分:

发现部分

视频:

视频

标签: phpmysqlcountfind

解决方案


UPDATE
    discover_section
SET amount =
    (
        SELECT 
            COUNT(id) 
        FROM 
            videos
        WHERE
                        -- only one hashtag saved
            videos.description LIKE TRIM(discover_section.section_name) OR 
            -- searched hashtag is the last hashtag, separator is space
            videos.description LIKE CONCAT("% ", discover_section.section_name) OR
            -- searched hashtag is the first hashtag, separator is space
            videos.description LIKE CONCAT(discover_section.section_name, " %") OR
            -- searched hashtag is one of the ceter hashtag, separator is space
            videos.description LIKE CONCAT("% ", discover_section.section_name, " %")
    );

推荐阅读