select afai.districtcode code,
count(afai.alarm_type = '2' or null ) forest_alarm,
count(afai.alarm_type = '1' or null ) non_forest_alarm,
count(afai.fire_type = '2' or null ) forest_fire,
count(afai.fire_type = '1' or null ) non_forest_fire,
afai.source_name district
from enbogis.bis_all_fire_alarm_index afai
WHERE 1=1
and source_lon is not null and source_lat is not null and fire_lon is not null and fire_lat is not NULL
group by afai.districtcode
having forest_fire>0 or non_forest_fire>0 or forest_alarm>0 or non_forest_alarm>0
错误信息
SQL 错误 [42803]: 错误: 字段 "afai.source_name" 必须出现在 GROUP BY 子句中或者在聚合函数中使用
Position: 285 At Line: 6, Line Position: 9
之前从mysql迁移到金仓数据库,数据迁移完成后,该后端的代码,就出现上面的错误按照提示修改过后确发现与原sql查询出来的数据不一样
修改过后的金仓sql多了很多条数据 不知道怎么办才好 希望各位帮帮我 钛痛苦了!!
参考GPT和自己的思路:根据错误信息提示,需要将字段 "afai.source_name" 放入 GROUP BY 子句中或者在聚合函数中使用,根据你提供的代码,需要将 afai.source_name 放入 GROUP BY 子句中,即将 "group by afai.districtcode" 修改为 "group by afai.districtcode, afai.source_name"。这样可以解决错误信息提示的问题。
至于数据量变化的问题,可能是迁移后金仓数据库中的数据不同于 MySQL 数据库中的数据,或者代码修改后查询条件有所改变,导致查询结果不同,需要进一步检查。建议对比 MySQL 数据库和金仓数据库中的数据,以及对比修改前后的代码和查询结果进行排查。
SELECT NAME,avg(hours)
FROM employee,works_on
WHERE
ssn = essn
AND essn IN (
SELECT DISTINCT a.essn
FROM works_on a,works_on b
WHERE
a.essn = b.essn
AND a.pno != b.pno
AND a.hours >= 100
AND b.hours >= 100
)
GROUP BY NAME