dongsheng6056 2017-09-02 14:19
浏览 49
已采纳

显示数据库中的主题标签

I have a problem, namely I want to display hashtags from such table "posts":

| id | author |   hashtags   |
|:------------|-------------:|
|  1 |  aaaa  | #aaa, #bbbb  | etc...
|  2 |  bbbb  | #ccc, #addd  |
|  3 |  cccc  | #aee, #ffff  |

The problem is that I would like to get something like this (only those records):

When I write a: #aaa, #addd, #aee
When I write b: #bbbb
etc...

How do I get the effect that only those hashtags that start with a letter (even in the same field) appear to me? I was thinking about regular expressions. Thanks in advance for any help.

  • 写回答

1条回答 默认 最新

  • douxiuyi6529 2017-09-02 14:30
    关注

    You need to make a couple of changes:

    • Move hashtags columns to a new table and store different hashtags in different rows (with post id as foreign key) i.e. normalize the table
    • use LIKE operator to query on the new table, e.g.

      SELECT hashtag
      FROM post_hashtag
      WHERE post_id = <id>
      AND hashtag LIKE '%#a%';`
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 哪个tomcat中startup一直一闪而过 找不出问题
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀
  • ¥50 求解vmware的网络模式问题 别拿AI回答
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网