php - 试图找到所有hastag计数并在MYSQL DB中插入一个数量
问题描述
我使用 PHP 和 MYSQL 数据库。
好的,所以我有 2 张桌子,一张被称为discover_section
,另一张被称为videos
。我想videos
在discover_section
.
例如,#plantAtree hastags 的数量在该video
部分中出现了 20 次。现在我想在discover_section
列中设置该金额。然后转到discover_section
(#test)中找到的下一个标签并查看在video
表中找到的次数等。
我该怎么做呢?
我的表如下所示:
发现部分:
视频:
解决方案
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, " %")
);
推荐阅读
- laravel - 当单击外部 div 时,vuejs 停止传播单击
- javascript - useEffect 缺少依赖项(使用 useContext 而不是 useState 时)
- javascript - 如何获取 DOM 中渲染的 Vue 组件的数量?
- python - Python:“myvar = 1000”有什么作用?
- tcl - 在 tcl 中打开 gnome-terminal 并运行脚本
- php - 有人知道如何根据字符串名称更改颜色吗?
- python - fernet 密钥错误“Fernet 密钥必须是 32 个 url 安全的 base64 编码字节”
- javascript - WP_NAV_MENU 不起作用,包括我的@Media 查询
- google-api - 通过 Google Drive API 获取共享驱动器创建者
- android - 带有导航组件后退箭头的导航抽屉在抽屉打开时不显示