mysql数据库中用数据库字段作为变量进行LIKE模糊查询!请看详细补充!
如:我要查询tb_mgoodsmoretype中编号为10,121的数据,并根据其编号gmt_Id_i在tb_mgoods表中统计这个编号对应的数据条数补充:goods_...
如:我要查询tb_mgoodsmoretype中编号为10,121的数据,并根据其编号gmt_Id_i 在tb_mgoods 表中统计这个编号对应的数据条数 补充:goods_MoreType_v的数据格式为[10][12],或者[121][1789]
select gmt_Id_i ,gmt_Name_v,
(select count(*) from tb_mgoods where goods_MoreType_v like '%gmt_Id_i%') as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121)
哦上面的条件是这样的 like '%[gmt_Id_i]%' 因为goods_MoreType_v的格式是这样的 [10][121]
请看清问题我是要用LIKE,不是直接等于!因为goods_MoreType_v数据格式是 [10][121] 之类的,而我的gmt_Id_i数据是编号 10 等
【select gmt_Id_i ,gmt_Name_v,
(select count(*) from tb_mgoods where goods_MoreType_v=tb_mgoodsmoretype.gmt_Id_i) as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121) 】 展开
select gmt_Id_i ,gmt_Name_v,
(select count(*) from tb_mgoods where goods_MoreType_v like '%gmt_Id_i%') as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121)
哦上面的条件是这样的 like '%[gmt_Id_i]%' 因为goods_MoreType_v的格式是这样的 [10][121]
请看清问题我是要用LIKE,不是直接等于!因为goods_MoreType_v数据格式是 [10][121] 之类的,而我的gmt_Id_i数据是编号 10 等
【select gmt_Id_i ,gmt_Name_v,
(select count(*) from tb_mgoods where goods_MoreType_v=tb_mgoodsmoretype.gmt_Id_i) as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121) 】 展开
3个回答
展开全部
select t.gmt_Id_i ,t.gmt_Name_v,
( select count(*) from tb_mgoods where goods_MoreType_v like '%/[' + t.gmt_Id_i + '/]%' escape '/') as counts
from tb_mgoodsmoretype t where t.gmt_Id_i in(10,121)
注意: like '%某字符串%' 等效于 like '%'+'某字符串'+'%',由于gmt_Id_i是字段名称,故不能使用 like '%gmt_Id_i%' 必须使用 like '%' + gmt_Id_i + '%' ,另外由于你的goods_MoreType_v字段含有[],必须使用转义符,把[]转为字符串[],否则,sql会理解[]为通配符使用,还有 sql中转义符\ 解释为把该字符后的第一个字母转成普通的字符。
( select count(*) from tb_mgoods where goods_MoreType_v like '%/[' + t.gmt_Id_i + '/]%' escape '/') as counts
from tb_mgoodsmoretype t where t.gmt_Id_i in(10,121)
注意: like '%某字符串%' 等效于 like '%'+'某字符串'+'%',由于gmt_Id_i是字段名称,故不能使用 like '%gmt_Id_i%' 必须使用 like '%' + gmt_Id_i + '%' ,另外由于你的goods_MoreType_v字段含有[],必须使用转义符,把[]转为字符串[],否则,sql会理解[]为通配符使用,还有 sql中转义符\ 解释为把该字符后的第一个字母转成普通的字符。
展开全部
select gmt_Id_i ,gmt_Name_v,
(select count(*) from tb_mgoods where goods_MoreType_v=tb_mgoodsmoretype.gmt_Id_i) as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121)
(select count(*) from tb_mgoods where goods_MoreType_v=tb_mgoodsmoretype.gmt_Id_i) as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
select gmt_Id_i ,gmt_Name_v,
(select count(*) from tb_mgoods where goods_MoreType_v=tb_mgoodsmoretype.gmt_Id_i) as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121)
(select count(*) from tb_mgoods where goods_MoreType_v=tb_mgoodsmoretype.gmt_Id_i) as counts
from tb_mgoodsmoretype where gmt_Id_i in(10,121)
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询