如何理解mysql中GROUP_CONCAT函数,过滤数据使用like %%


	select * from (
SELECT f.package_sid AS packageId,
			GROUP_CONCAT(cast(FEATURE_SID as char))
			AS features 
					FROM (SELECT     fp.package_sid,fp.FEATURE_SID FROM tb_feature_package fp ORDER BY fp.FEATURE_SID) f
					GROUP BY f.package_sid 

)s
 where s.features like
			           '%29046%29156%'

412 29011,28971,28985,29176,29141,29036,28933,29015,29040,28990,29168,28961,29018,29171,29064,28926,28947,29079,29046,29156,28956,28975,29209,29008,29196,28928,29089,29114,29165,28983,28987,28924,29051,29061,29072,28965,28949,29083,29103,29122,29005,29013,29027,29127,29177,29195,28919,29056,29198,29052,29131,28963,29143,28940,28968,28992,28950

465 28918,29060,29170,29089,28947,28924,29046,29049,28944,28919,29166,28975,29151,30069,29077,29196,28928,28963,29097,29114,29141,29051,28937,29056,28979,29099,29023,29191,29034,29058,28949,29122,28967,29027,28956,28994,29012,29225,29079,29131,29198,29156,29059,29209,28992,29042,28957,29159,29215,28965,29013,29157,29180,29142,29200,28939,29083

为什么用的是 like %%

car
浏览 4198回答 3
3回答

MinRam

%表示允许此处字符串替代所以: like  '%29046%29156%' 为真有以下情况19029046992915600   2904692915672904629156即只要依次出现29046和29156即可为真

MinRam

%代表任意长度(长度可为0)的字符串,(a%b可表示a开头,b结尾的任意长度字符串)例子如下:select *  from student  where name like 'a';此时要求name = 'a’;select *  from student where name like '%a'此时 name 可以为 '123a' , '21a','a' 等,但是不能为 'a123'  ;即%a,可看成任意长度字符串+a,只要name满足即可为真。select *  from student where name like '%a%'此时name 可以为'123a321','1a23','a','a23','12a' ;即%a%,可看成任意长度字符串+a+任意长度字符串,只要name满足即可。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL