请教个like语句的问题

assassain 2018-03-19 10:57:51
A表是流程主表,AID是记录流程参与者的ID,但是是字符串,以,,2,,3,,4的形式多个记录在AID这个字段里面。
B表是用户表,BID是用户ID,BName是用户登录名

select count(*) from A where AID like '%,29,%' 读取正常


用户登录时我想通过用户名去匹配B表当前用户的ID,能否用数据库语句直接实现?
我把29换成下面就读不出来了。
select count(*) from A where AID like '%,(select BID from B where BName=''jay''),%'

请教各位大神正确的应该怎么写?

不用存储过程
...全文
266 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
assassain 2018-03-19
  • 打赏
  • 举报
回复
引用 1 楼 weixin_39646155 的回复:
你试试这个语句 select count(*) from A where AID like concat('%,',(select BID from B where BName=''jay''),',%');
换成'jay'候, concat不是有效的内置函数名
assassain 2018-03-19
  • 打赏
  • 举报
回复
引用 2 楼 weixin_39646155 的回复:
[quote=引用 1 楼 weixin_39646155 的回复:] 你试试这个语句 select count(*) from A where AID like concat('%,',(select BID from B where BName=''jay''),',%');
把"jay"换成'jay'[/quote] 换成'jay'后,是语法错误
G.Jagger 2018-03-19
  • 打赏
  • 举报
回复
引用 1 楼 weixin_39646155 的回复:
你试试这个语句 select count(*) from A where AID like concat('%,',(select BID from B where BName=''jay''),',%');
把"jay"换成'jay'
G.Jagger 2018-03-19
  • 打赏
  • 举报
回复
你试试这个语句 select count(*) from A where AID like concat('%,',(select BID from B where BName=''jay''),',%');
assassain 2018-03-19
  • 打赏
  • 举报
回复
引用 8 楼 roy_88 的回复:
这是MYSQL版?提你SQL SERVER,发错版块了 SQL SERVER08没用CONCAT,改为
 select count(*) from A where exists(select 1 from B where BName='jay' and a.AID like '%,'+RTRIM(BID)+',%')
谢谢,按照你的方式解决了。
中国风 2018-03-19
  • 打赏
  • 举报
回复
这是MYSQL版?提你SQL SERVER,发错版块了 SQL SERVER08没用CONCAT,改为
 select count(*) from A where exists(select 1 from B where BName='jay' and a.AID like '%,'+RTRIM(BID)+',%')
assassain 2018-03-19
  • 打赏
  • 举报
回复
select count(*) from tba where  (ActorsID like '%,(select K_AccountID from Account where AccountName=''登录名''),%')
我现在是这样写的。是没报错,但是查询不出来
assassain 2018-03-19
  • 打赏
  • 举报
回复
引用 5 楼 roy_88 的回复:
AID类型是不是?
select BID from B where BName=''jay'')
--这条件是不是只有一条记录 ------------满足以上条件时,不会报错 结果集存在多少记录时,必须改为子查询条件如下: e.g.
 select count(*) from A where exists(select 1 from B where BName='jay' and AID like concat('%,',BID,',%'))
AID是nvachar的,BID是int select BID from B where BName=''jay'') 这个记录确定只有一条。 但是concat函数在SQL08里面提示不是有效的内置函数。
中国风 2018-03-19
  • 打赏
  • 举报
回复
AID类型是不是?
select BID from B where BName=''jay'')
--这条件是不是只有一条记录 ------------满足以上条件时,不会报错 结果集存在多少记录时,必须改为子查询条件如下: e.g.
 select count(*) from A where exists(select 1 from B where BName='jay' and AID like concat('%,',BID,',%'))

56,679

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧