如何获取knex中按此列分组的列中的条目数

时间:2016-10-04 16:08:25

标签: javascript sql node.js postgresql knex.js

我正在尝试将以下SQL查询转换为knex.js:

select name, count(name)
from mytable
group by name;

它返回:

name | count 
-----+-------
greg |     2
john |     1

我试过了:

knex
  .select(['name'])
  .count('name as count')
  .groupBy('name')
  .from('mytable');

// ...
// console.log(result)

输出结果为:

[ anonymous { name: 'greg', count: '2' },
  anonymous { name: 'john', count: '1' } ]

什么是anonymous?我做错了什么?

0 个答案:

没有答案