怎么解决sequelize会在order中那个参数自动加上表的别名
发布于 4 天前 作者 mosaic101 143 次浏览 来自 问答

code

attributes: [
                sequelize.literal('SUM(stock) AS stock'),
                sequelize.literal('SUM(actualAmount) AS actualAmount'),
                sequelize.literal('SUM(differAmount) AS differAmount'),
                sequelize.literal('SUM(beforeInventorySum) AS beforeInventorySum'),
                sequelize.literal('SUM(afterInventorySum) AS afterInventorySum')
            ],
            group: 'GoodId',
            order: ['differAmount','desc']

sql

SELECT
	SUM(stock) AS stock,
	SUM(actualAmount) AS actualAmount,
	SUM(differAmount) AS differAmount,
	SUM(beforeInventorySum) AS beforeInventorySum,
	SUM(afterInventorySum) AS afterInventorySum
FROM
	`inventory_result_details` AS `InventoryResultDetail`
GROUP BY
	GoodId
ORDER BY
	`InventoryResultDetail`.`differAmount` DESC

sequelize版本3.2,我想针对分组后的数据再排序,sequelize会在order中那个参数自动加上表的别名,导致数据有问题

3 回复

sequlize.col(‘column’) From Noder

@zhengnz 这个我在issues里看到了,就是不知道怎么加asc、desc,官方api没找到,如果方便贴一下此方法api,谢谢

[sequelize.col(‘column’), ‘asc’] From Noder

回到顶部