gpt4 book ai didi

mysql - 如何在 sequelize 中编写嵌套的 select 语句?

转载 作者:行者123 更新时间:2023-12-03 22:24:59 25 4
gpt4 key购买 nike

我的问题是如何使用 sequelize.js 编写嵌套的 select 语句,这是我需要实现的:

SELECT * from (SELECT id, time FROM table_name ORDER BY time desc) AS `descTime` GROUP BY `id`;
我试过这个代码
User.findAll({
attributes: [[Sequelize.literal('(SELECT id, time FROM table_name ORDER BY time desc)'),
'descTime']],
group: ['id'],
});
但它没有用

最佳答案

你可以通过这个查询得到我猜你想要的。它比您在问题中的要简单一些,并且其结果集更可预测。

 SELECT id, MAX(`time`) `time` FROM table_name GROUP BY id

关于mysql - 如何在 sequelize 中编写嵌套的 select 语句?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64895251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com