mysql - SQL错误(1111):无效使用组函数

标签 mysql

我正在尝试获取(entrydate列中的最大日期)和(entrydate列中的最大日期-15天)之间的数据!

表1:总共有953行


表2:总共有400行


我收到此错误,请帮助我!

    Select  
o_material_transaction_inward.Mat_Code,
s_material_details.Mat_Spec,
s_material_details.Mat_Make,
o_material_transaction_inward.Sup_Name,
o_material_transaction_inward.Entry_Date,
o_material_transaction_inward.DC_qty,
o_material_transaction_inward.Received_qty,
    from 
o_material_transaction_inward 
    join 
s_material_details 
    on 
s_material_details.Mat_Code=o_material_transaction_inward.Mat_Code and s_material_details.Mat_Group_Id=o_material_transaction_inward.Mat_Group_id
    where 
o_material_transaction_inward.Entry_Date between Max(o_material_transaction_inward.Entry_Date) and Max(o_material_transaction_inward.Entry_Date - 15)

最佳答案

更新:固定的BETWEEN谓词:

它不起作用的原因是最小值必须是BETWEEN谓词中的第一个值,因此为了从两个表中获得entry_date在最大输入日期-15和最大之间的那些行录入日期请尝试:

SELECT
  o.Mat_Code,
  s.Mat_Spec,
  s.Mat_Make,
  o.Sup_Name,
  DATE_FORMAT(o.Entry_Date, '%Y-%m-%d') AS Entry_Date,
  o.DC_qty,
  o.Received_qty
FROM o_material_transaction_inward AS o
INNER JOIN s_material_details      AS s  ON s.Mat_Code     = o.Mat_Code
WHERE o.Entry_Date BETWEEN ((SELECT Max(Entry_Date) 
                            FROM o_material_transaction_inward) - 15)
                       AND (SELECT Max(Entry_Date) 
                            FROM o_material_transaction_inward) ;


SQL Fiddle Demo

关于mysql - SQL错误(1111):无效使用组函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14707840/

相关文章:

mysql - 需要帮助在 VB.net 中编写一个循环以根据远程 sql db 中的用户名在 Windows 中创建文件夹

mysql - 使用 awk 或 sed 将 mysql.log 重新格式化为简单格式

mysql - Rails 迁移 : update_all with dynamic code is possible?

mysql - VB.net MySQL 更新 ListView 中的所有项目

mysql - 如何将SQL Server程序转换为MySQL?

mysql - 如何从 MySQL Select 中删除不完整的结果

php - 如何从 2 个有条件的表中删除

mysql - 填充 MySQL 数据库中的字段

android - 将 MySQL 工作台连接到 Eclipse

php - 如何将以下三个 Laravel Eloquent 查询合并为一个?