1👍
✅
The following SQL statement groups entries by day/month/year and computes the sum of the token numbers per day/month/year group:
select sum(prompt_tokens) as sum_prompt_tokens,
sum(completion_tokens) as sum_completion_tokens,
sum(total_tokens) as sum_total_tokens,
extract(day from timestamp created) as day,
extract(month from timestamp created) as month,
extract(year from timestamp created) as year
from "<your table>"
group by
extract(day from timestamp created),
extract(month from timestamp created),
extract(year from timestamp created)
If sequelize does not allow the extract
expressions, you can alternatively use a data model where date and time are already separated:
{
"uuid": "123",
"prompt_tokens": 208,
"completion_tokens": 53,
"total_tokens": 261,
"createdDate": "2022-12-20",
"createdTime": "15:45:40.730"
}
Then the SQL statement becomes
select sum(prompt_tokens) as sum_prompt_tokens,
sum(completion_tokens) as sum_completion_tokens,
sum(total_tokens) as sum_total_tokens,
createdDate
from "<your table>"
group by createdDate
Source:stackexchange.com