Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing custom functions in Sequelize Attribute

I have a MySQL query that looks like this:

SELECT (SUM(total_time * actual_fte) / SUM(total_time)) AS actual_fte FROM USERS GROUP BY HOUR(timestamp)

I'm assuming it's some type of variant of this type of function:

attributes: [[models.sequelize.fn('SUM',models.sequelize.col('total_time')),'total_time']]

So, how would I turn this MySQL query into the sequelize version?

like image 388
Jonathan Avatar asked Apr 22 '26 18:04

Jonathan


1 Answers

Use Sequelize.literal... It will be ok and you can do anything what you want ;)

like image 166
João Silva Avatar answered Apr 24 '26 08:04

João Silva



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!