分组查询
group()
分组查询数据,需要传按哪个字段分组
- @param
field
字段名
group()
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).field('id, max(score)').group('id').select()
return user
})
import { Db } from 'think-ts-db'
export default defineEventHandler(async (event) => {
const user = await Db('user', mysqlConfig).field('id, max(score)').group('id').select()
return user
})
最终的SQL语句为:
SELECT id, max(score) FROM user GROUP BY id
SELECT id, max(score) FROM user GROUP BY id