小小少年QAQ 2023-05-17 16:53 采纳率: 31.6%
浏览 12

mysql迁移金仓数据库中分组的问题


 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多了很多条数据 不知道怎么办才好 希望各位帮帮我 钛痛苦了!!

  • 写回答

2条回答 默认 最新

  • 「已注销」 2023-05-17 17:15
    关注

    参考GPT和自己的思路:根据错误信息提示,需要将字段 "afai.source_name" 放入 GROUP BY 子句中或者在聚合函数中使用,根据你提供的代码,需要将 afai.source_name 放入 GROUP BY 子句中,即将 "group by afai.districtcode" 修改为 "group by afai.districtcode, afai.source_name"。这样可以解决错误信息提示的问题。

    至于数据量变化的问题,可能是迁移后金仓数据库中的数据不同于 MySQL 数据库中的数据,或者代码修改后查询条件有所改变,导致查询结果不同,需要进一步检查。建议对比 MySQL 数据库和金仓数据库中的数据,以及对比修改前后的代码和查询结果进行排查。

    评论

报告相同问题?

问题事件

  • 创建了问题 5月17日

悬赏问题

  • ¥15 如何入门学习c语言,单片机
  • ¥15 idea 编辑语言的选择
  • ¥15 Windows下部署Asmjit
  • ¥15 请问双层规划模型的上下层目标函数不一致,是如何保证迭代收敛性的
  • ¥15 微信小程序 前端页面内容搜索
  • ¥15 cpu是如何判断当前指令已经执行完毕,然后去执行下条指令的
  • ¥15 安装visual studio2022时visualstudiosetup启动不了,闪退。问题代号0x0和0x1389
  • ¥30 java spring boot2.5.3版本websocket连不上
  • ¥15 angular js调外部链接查看pdf
  • ¥15 openFOAM DPMFoam