【问题标题】:MySql Select from colonMySql 从冒号中选择
【发布时间】:2012-10-04 07:37:44
【问题描述】:

表:用户

| user_Id  | my_threads          |               
| 100      | 200:1, 201:2, 217:4 |
| 101      | 200:1, 215:3, 217:4 |

表:线程

| thread_id | author_id | title                     |
| 217       | 100       | This is title thread      |
| 200       | 101       | this is only test         |

当用户登录成功$userId=user_Id,显示该用户线程的标题?

select title 
from thread
where FIND_IN_SET(thread.thread_id,(select my_threads from user where user_id=100));

当 my_threads 没有像这样的冒号 200、217 时,上面的这个 sql 有效

【问题讨论】:

  • 我不明白。问题是什么?

标签: mysql comma


【解决方案1】:

试试这个:

将冒号替换为逗号

select title 
from thread
where FIND_IN_SET(thread.thread_id,
        (select replace(replace(my_threads,':',','),' ','') from user where user_id=100))


SQL fiddle demo

【讨论】:

  • 这个 sql 给了我 2 个标题 (200:1) 给了我 (200 + 1) 我只需要线程 (200)。
  • @user1710911:请查看答案中更新的 SQL 小提琴
  • 感谢您的帮助。但正如您所见,user_id 100 有 2 个标题 200+217 sql fiddle 只给了我 1 个
猜你喜欢
  • 2011-10-21
  • 1970-01-01
  • 2011-10-25
  • 1970-01-01
  • 2016-04-05
  • 2012-09-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多