我在我的nodeJS应用上使用sequelize来查询sql数据库。
我试图对这个查询进行序列化,但它不起作用……
有人能帮我吗?
`SELECT content, COUNT(*) count FROM `hashtags` GROUP BY content ORDER BY count DESC LIMIT 10`我试着
Tags.findAll({group: ['content'], attributes: ['content', [sequelize.fn('COUNT', 'content'), 'content']],}).then(function(results) {标签是用date、content、id_tweet、id定义序列化。
我有另一个查询,但我没有任何想法这样做,因为有2个内部连接和计数:
SELECT COUNT(*) AS nombredetweets, h.content, u.pseudo FROM tweets t INNER JOIN hashtags h ON t.id = h.id_tweet INNER JOIN user u ON t.id_user = u.id WHERE h.content = ? AND u.pseudo = ?谢谢;)
发布于 2018-05-28 23:53:02
看起来问题出在如何命名计数结果上。试试这个:
Tags.findAll({
group: ['content'],
attributes: [
'content',
[
sequelize.fn('COUNT', 'content'),
'count'
]
],
order: [['count', 'DESC']],
limit: 10,
}).then(function(results) {
// ...
})https://stackoverflow.com/questions/50556121
复制相似问题