APPCUBE-脚本代码性能检查规则说明:规则6:SELECT语句中聚集函数必须增加别名

时间:2023-11-01 16:19:13

规则6:SELECT语句中聚集函数必须增加别名

SELECT语句中聚合函数必须使用别名方式存储查询结果,以免因聚合函数返回的结果不一致,导致存在兼容性问题。

  • 错误代码示例:
    import * as db from 'db';let errorDemo = db.sql().exec("select count(*) from object_demo where object_name = 'HuaWei'")
  • 正确代码示例:
    import * as db from 'db';let correctDemo = db.sql().exec("select count(*) as count from object_demo where object_name = 'HuaWei'")
  • 推荐代码示例:
    ***聚合函数示例 ****select count(*) as count_res,select max(*) as max_res,select min(*) as min_res,select avg(*) as avg_res,select sum(*) as sum_res  

该规则在版本1.3.3中被引入。

support.huaweicloud.com/usermanual-appcube/appcube_05_05001.html