title: How to write formula in ORDER using fields from subquery
body: <p>I need to implement sorting on computed data from a subquery. There is a request like this:</p>
  <pre><code>const res = await db.order.findAndCountAll({
      limit: 10,
      offset: (page - 1) * 10,
      distinct: true,
      order: [[db.sequelize.literal('product.taxes * product.count'), 'ASC']],
      where,
      include: [
        { model: db.location },
        { model: db.address },
        {
          model: db.order_product,
          as: 'products',
          required: true,
          include: [
            {
              model: db.product,
              include: [{ model: db.location }],
            },
          ],
        },
      ],
    });
  </code></pre>
  <p>This code is not working. I get the error:</p>
  <blockquote>
  <p>missing FROM-clause entry for table &quot;product&quot;</p>
  </blockquote>
  <p>In line:order: [[db.sequelize.literal('<strong>product.taxes</strong> * <strong>product.count</strong>'), 'ASC']], i want to use to calculate the fields that are in the db.product model which i am accessing in a sub-sub-query. Moreover, this sub-sub-query will return an array, and I need to execute (db.product.amount * db.product.price) for each element of the array and then add up all the resulting products. How to describe this formula in &quot;order&quot;?
  Maybe I chose the wrong path. What is the best way to sort by calculated data from a subquery?</p>