dev﹫localhost
dev﹫localhost
KKysely
Created by dev﹫localhost on 4/27/2024 in #help
How to cast to date. eg : `DATE(created_at)`
How to write this query in kysely
SELECT DATE(created_at) AS date, SUM(points) AS score
FROM table
WHERE id = '...'
GROUP BY date
ORDER BY date;
SELECT DATE(created_at) AS date, SUM(points) AS score
FROM table
WHERE id = '...'
GROUP BY date
ORDER BY date;
My attempt
const result = await db
.selectFrom('table')
.select(({ fn }) => [
fn.sum<number>('table.points').as('score')
])
.where('id', '=', id)
// .groupBy('created_at')
// .orderBy('created_at')
.execute()
const result = await db
.selectFrom('table')
.select(({ fn }) => [
fn.sum<number>('table.points').as('score')
])
.where('id', '=', id)
// .groupBy('created_at')
// .orderBy('created_at')
.execute()
5 replies