gpt4 book ai didi

sql - 如何将此 SQL 查询转换为 sequelize?

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

SELECT
"flatNo",
"buildingId",
count(*)
FROM "FlatDetails"
WHERE "buildingId"= 'E7EA2771'
GROUP BY
"flatNo",
"buildingId"
HAVING count(*) > 1;

我试过这个工具 https://pontaku-tools.com/english/ 但它没有给我正确的答案。

最佳答案

你可以试试这个代码。关键字是 fn & literal

FlatDetails.findAll({
attributes: ['flatNo', 'buildingId', [sequelize.fn('count', sequelize.col('*')), 'count']],
where: {
buildingId: 'E7EA2771'
},
group: ['flatNo', 'buildingId'],
having: sequelize.literal('count(*) > 1'),
raw: true,
logging: true
})
.then(flats => {
console.log(flats);
})
.catch(err => {
console.log(err);
})

关于sql - 如何将此 SQL 查询转换为 sequelize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60276787/

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