问题:系统自动产生一条数据:例如:11271851,13670999,22306155, 需要与mysql中的表table1进行join查询,join条件为 column1 = 11271851(按,分隔后的列)
解决方式:1,将数据转换为临时表:
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(tempAdzone.adzone, ',', numbers.n), ',', -1) adzone
FROM(SELECT 1 AS n
UNION ALL SELECT 2
UNION ALL SELECT 3
) numbers INNER JOIN ( SELECT "11271851,13670999,22306155" AS adzone ) tempAdzone
ON CHAR_LENGTH(tempAdzone.adzone) - CHAR_LENGTH(REPLACE(tempAdzone.adzone, ',', '')) >= numbers.n-1
2, 临时表与mysql数据库join查询
... ...
或者:
在后端系统生成类似下面的语句(懒了,直接贴段代码)
adzoneList = [11271851,13670999,22306155]
StringBuilder adzoneSb = new StringBuilder();
adzoneSb.append("SELECT '"+adzoneList.get(0)+"' AS adzone ");
for(int i=1; i< adzoneList.size(); i++){
adzoneSb.append(" UNION ALL SELECT '"+adzoneList.get(i)+"'");
}
adzoneSb.toString() 得到的语句即可在mysql中直接执行