{ "properties" : { }, "id" : "7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2", "script" : null, "groupId" : "f8e3d2c1b0a94e5f8a7b6c5d4e3f2a1", "name" : "牦牛销售类型统计", "createTime" : 1780880400000, "updateTime" : 1781375000000, "lock" : null, "createBy" : "admin", "updateBy" : "admin", "path" : "/yak-sales-type-stats", "method" : "GET", "parameters" : [ ], "options" : [ ], "requestBody" : "", "headers" : [ ], "paths" : [ ], "responseBody" : null, "description" : "牦牛销售类型统计:gov_count_order_total 按 purpose 分组,SUM(yak_number) 为成交头数,一条记录一单。", "requestBodyDefinition" : null, "responseBodyDefinition" : null } ================================ // gov_count_order_total:一条记录 = 一笔订单 // 成交头数:SUM(yak_number) // 销售类型:purpose(屠宰 / 养殖 / 其他 等) var sql = """ SELECT COALESCE(NULLIF(TRIM(purpose), ''), '其他') AS name, COALESCE(SUM(yak_number), 0) AS value FROM gov_count_order_total GROUP BY COALESCE(NULLIF(TRIM(purpose), ''), '其他') ORDER BY value DESC """ var rows = db.select(sql) var total = 0 for (row in rows) { var count = row.value != null ? row.value : 0 total = total + count } var result = [] for (row in rows) { var count = row.value != null ? row.value : 0 var percent = 0 if (total > 0) { percent = (count * 100.0) / total } result.push({ name: row.name, value: count, percent: percent }) } return result