Unknown column 'SOURCEURLS' in 'field list' 存在问题的MySQL语句是: "SELECT DATE, SUM(IF(country='"+mother1['mother1']+"',1,0)) AS "+mother1['mother1']+", SUM(IF(country='"+mother2['mother2']+"',1,0)) AS "+mother2['mother2']+", SUM(IF(country='"+mother3['mother3']+"',1,0)) AS "+mother3['mother3']+", SUM(IF(country='"+mother4['mother4']+"',1,0)) AS "+mother4['mother4']+" ,SOURCEURLS FROM (SELECT DATE, SUBSTRING_INDEX(SUBSTRING_INDEX(locations, '#', 3), '#', -1) AS country FROM chatgptgkg) subquery where locate('" +ctx['rlt'] + "',SOURCEURLS) AND SQLDATE>=" + starttime['start'] + " and SQLDATE<= "+endtime['end']+" GROUP BY date ORDER BY date;",如果想定位SOURCEURLS中存在某字符,该如何修改?
时间: 2023-06-16 15:04:57 浏览: 169
可以将查询条件改为使用 LIKE 操作符,如下所示:
"SELECT DATE, SUM(IF(country='"+mother1['mother1']+"',1,0)) AS "+mother1['mother1']+", SUM(IF(country='"+mother2['mother2']+"',1,0)) AS "+mother2['mother2']+", SUM(IF(country='"+mother3['mother3']+"',1,0)) AS "+mother3['mother3']+", SUM(IF(country='"+mother4['mother4']+"',1,0)) AS "+mother4['mother4']+" ,SOURCEURLS FROM (SELECT DATE, SUBSTRING_INDEX(SUBSTRING_INDEX(locations, '#', 3), '#', -1) AS country, SOURCEURLS FROM chatgptgkg) subquery where SOURCEURLS LIKE '%" +ctx['rlt'] + "%' AND SQLDATE>=" + starttime['start'] + " and SQLDATE<= "+endtime['end']+" GROUP BY date ORDER BY date;"
此处将原查询语句中的 "locate('" +ctx['rlt'] + "',SOURCEURLS)" 改为 "SOURCEURLS LIKE '%" +ctx['rlt'] + "%'",意为 SOURCEURLS 中包含 ctx['rlt'] 的子串即可。
阅读全文