AM在我的带有WAMP服务器的Windows PC上使用MySQL 5.7.13
这里我的问题是在执行此查询时
SELECT *
FROM `tbl_customer_pod_uploads`
WHERE `load_id` = '78' AND
`status` = 'Active'
GROUP BY `proof_type`
Run Code Online (Sandbox Code Playgroud)
我总是得到这样的错误
SELECT列表的表达式#1不在GROUP BY子句中,并且包含非聚合列'returntr_prod.tbl_customer_pod_uploads.id',它在功能上不依赖于GROUP BY子句中的列; 这与sql_mode = only_full_group_by不兼容
你能告诉我最好的解决方案吗?
我需要像结果一样
+----+---------+---------+---------+----------+-----------+------------+---------------+--------------+------------+--------+---------------------+---------------------+
| id | user_id | load_id | bill_id | latitude | langitude | proof_type | document_type | file_name | is_private | status | createdon | updatedon |
+----+---------+---------+---------+----------+-----------+------------+---------------+--------------+------------+--------+---------------------+---------------------+
| 1 | 1 | 78 | 1 | 21.1212 | 21.5454 | 1 | 1 | id_Card.docx | 0 | Active | …Run Code Online (Sandbox Code Playgroud) 我有两个表:书籍和文章,它们之间有多对多的关系.加入表是BookArticles.
车型/ books.js
module.exports = function(sequelize, DataTypes) {
return Food = sequelize.define("Book", {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true,
unique: true
}
});
}
Run Code Online (Sandbox Code Playgroud)
车型/ articles.js
module.exports = function(sequelize, DataTypes) {
return Food = sequelize.define("Article", {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true,
unique: true
}
});
}
Run Code Online (Sandbox Code Playgroud)
车型/ bookArticles.js
module.exports = function(sequelize, DataTypes) {
return Food = sequelize.define("BookArticles", {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
allowNull: false,
autoIncrement: true,
unique: true
}, …Run Code Online (Sandbox Code Playgroud) Sequelize 版本:4.22.6,MySql 版本:5.7.8 我想在查询执行中在属性(在 _user_count_ 的位置)中“hasMany”关联(CompanyUser)计数
/**
* Company user associate with Company with belongsTo relation
*/
`CompanyUser.belongsTo(Company, { foreignKey: 'company_id', targetKey: 'id'});`
/**
* Company associate with Company user with hasMany relation
*/
`Company.hasMany(CompanyUser, { foreignKey: 'company_id', sourceKey: 'id'});`
`return Company.findAll({
attributes: [
'id', 'title', 'is_enabled', '_user_count_'
]
include: [
{
model: sqConn.CompanyUser,
attributes: ['id'],
},
{
model: sqConn.CompanyLogo,
attributes:['file_object'],
}
],
}).then(function(model) {
return sequelize.Promise.resolve(model);
}).catch(function(err) {
return sequelize.Promise.reject(err);
});`
Run Code Online (Sandbox Code Playgroud)
带有左连接的简单 MySQL 查询工作正常并给出计数。
我正在尝试将此查询转换为序列化查询对象,正确的方法是什么?
SELECT families.id, count('answers.familyId') FROM families LEFT JOIN
answers on families.id = answers.familyId WHERE answers.isActive=1 AND
answers.answer=1 GROUP BY families.id HAVING COUNT('answers.familyId')>=6
Run Code Online (Sandbox Code Playgroud)