Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 如何计算最近一次处理的文件数是昨天_Mysql_Date_Max_Where Clause - Fatal编程技术网

Mysql 如何计算最近一次处理的文件数是昨天

Mysql 如何计算最近一次处理的文件数是昨天,mysql,date,max,where-clause,Mysql,Date,Max,Where Clause,我有多个表,我想检查分配给用户的文件数量,但他今天没有处理这些文件。我已经写了下面的查询,但是下面有一个错误 1111-组函数的使用无效 请帮我检查错误您不能在where子句中使用聚合函数。如果您想这样做,您需要: 定义分组字段,即添加group by子句 对having子句中的分组字段或聚合字段设置任何条件。 select查询的正确语法为: SELECT -- Your fields and/or expressions FROM -- Your data sources (tables, v

我有多个表,我想检查分配给用户的文件数量,但他今天没有处理这些文件。我已经写了下面的查询,但是下面有一个错误

1111-组函数的使用无效
请帮我检查错误

您不能在where子句中使用聚合函数。如果您想这样做,您需要:

定义分组字段,即添加group by子句 对having子句中的分组字段或聚合字段设置任何条件。 select查询的正确语法为:

SELECT -- Your fields and/or expressions
FROM -- Your data sources (tables, views and/or subqueries), and joins
WHERE -- Conditions on the "raw" data
GROUP BY -- Grouping fields
HAVING -- Conditions on grouped and/or aggregated data
ORDER BY -- Ordering fields
如果希望任务列表记录的最后一个任务日期为24小时:

select id, max(task_date) as max_task_date
from task_list
where 
    task_date <= date_add(now(), interval -1 day)
    -- maybe you need something like: task_date <= date_add(curdate(), interval -1 day)
group by id;

我把剩下的留给你。。。您可以将此结果与其他表合并以获取所需信息。

使用子查询获取每个案例文件的最大日期,然后计算外部查询中符合条件的数量:

select count(*)
from (
  SELECT t1.cfid as cfid, MAX(t2.task_date) d
  FROM task_list t2 
  INNER JOIN case_files t1 ON t2.cfid=t1.cfid 
  INNER JOIN case_file_allocations t3 ON t2.cfid=t3.cfid 
  WHERE t2.worked<>'yes' AND t2.acm=t3.acm AND t2.acm='310' AND t2.deleted<>1 
    AND t1.closed<>'yes' AND t1.deleted<>1 AND t1.pool_id IN(0,1) 
    AND t3.reallocated<>'yes'
  group by t1.cfid) a
where d < NOW();

错误是指max..I t我想我会使用max o count only记录,直到昨天才工作在您的查询中MAXt2.task_date是什么意思?我只需要在task_list表中找到最近工作时间是昨天的文件数,因此同一任务可能会在该表中多次显示,您对最新的记录感兴趣吗?我如何实现上述目标?任务列表中是否有多条记录具有相同的id和不同的日期?上述查询是否只计算到昨天还未工作的文件,并将这些文件保留到今天@Fabricator@leboMagma,测试一下。如果不起作用,请发布表模式、测试样本和预期结果。
select count(*)
from (
  SELECT t1.cfid as cfid, MAX(t2.task_date) d
  FROM task_list t2 
  INNER JOIN case_files t1 ON t2.cfid=t1.cfid 
  INNER JOIN case_file_allocations t3 ON t2.cfid=t3.cfid 
  WHERE t2.worked<>'yes' AND t2.acm=t3.acm AND t2.acm='310' AND t2.deleted<>1 
    AND t1.closed<>'yes' AND t1.deleted<>1 AND t1.pool_id IN(0,1) 
    AND t3.reallocated<>'yes'
  group by t1.cfid) a
where d < NOW();