How can I minus a value from 2 columns and then apply the maximum function in sequelizejs?

I am trying to get the maximum record after the value minus 2 columns. I can make this request on phpMyAdmin

SELECT `storage_id`, `host` FROM `storages` 
WHERE size - used = (SELECT MAX(size - used) FROM `storages`

but struggling with the consequences. Any help?

Updated:

I updated my query and now it is easier than the previous one.

SELECT `storage_id`, `host`, size - used AS free FROM `storages` ORDER BY free DESC LIMIT 1
+4
source share
1 answer

I found Sequelize.literal that helped me achieve this in Sequelize.

Storage.findOne({
    attributes: ['storage_id', 'host', [Sequelize.literal('size - used'), 'free']],
    order: 'free DESC'
  })
+4
source

Source: https://habr.com/ru/post/1666940/


All Articles