knex.tables.tests
.select('userId', knex.raw('SUM(score) as scores'))
.whereIn('score', [70,80,90])
.whereBetween('created', [start, end])
.groupByRaw('userId')
.orderBy('scores', 'desc')
.limit(10)
-
Raw
执行原始的sql语句的请求。
knex.raw(sql, bindings) -
groupBy
.groupBy(*names)
a group
knex('tests').groupBy('userId')
select * from `tests` group by `userId`
- groupByRaw
.groupByRaw(sql)
a raw group
在group分组的基础上,再进行统计数据。
knex
.select('userId', knex.raw('SUM(score)'))
.from('tests')
.groupByRaw('userId WITH ROLLUP')
select userId, SUM(score) from `tests` group by userId WITH ROLLUP
- orderBy
.orde