Mysql中数据周智慧的老化

时间:2015-02-17 11:20:50

标签: mysql

这里我有一个任务表,其中包含task_id,created_date,completed_date,priority。

我需要输出能够优先获得记录,而不会打开周任务。 如果completed_date为null,则应计算与当前日期的差异。

我需要mysql查询,返回我的记录,如

-----------------------------------------------------------------
|week of created | priority  | Count   |   no of week task open |
-----------------------------------------------------------------
|40              | hi        | 20      | 2(week diff of completed |
                                         and create date)

这是在完成日期存在时向我提供数据的查询。

select yearweek(created_Date) AS year_week
     , priority, count(*) as cnt
     , yearweek(completed_date) - yearweek(created_date) as Diff 
  from lss_analyseTaskLogView 
 where diffs is not null 
   and diffs <> '' 
   and completed_date is not null 
   and completed_Date <> '0000-00-00' 
 group 
    by Diff
     , priority;

这是在完成日期不存在时向我提供数据的查询。

select yearweek(created_Date) as year_week
     , priority
     , count(*) as cnt
     , yearweek(CURRENT_DATE) - yearweek(created_date) as Diff 
  from lss_analyseTaskLogView 
 where diffs is not null 
   and diffs <> '' 
   and (completed_date is null or completed_Date = '0000-00-00 00:00') 
 group 
    by Diff
     , priority;

当使用查询

时,我在周差和优先级相同的情况下结合了两个查询的计数
select A.year_week, A.priority, A.cnt + B.cnt As Cnt, A.Diff  from
(select yearweek(created_Date) AS year_week ,priority, count(*) as cnt,
yearweek(completed_date) - yearweek(created_date) as Diff
from lss_analyseTaskLogView
where diffs is not null and diffs <> '' and completed_date is not null
and completed_Date <> '0000-00-00' group by Diff,priority) A,
(select yearweek(created_Date) as year_week,priority, count(*) as cnt,
yearweek(CURRENT_DATE) - yearweek(created_date) as Diff
from lss_analyseTaskLogView
where diffs is not null and diffs <> ''
and (completed_date is null or completed_Date = '0000-00-00 00:00')
group by Diff,priority) B
where A.Diff = B.Diff and A.priority = B.priority and A.year_week = B.year_week;

但是如何获得前两个查询的记录,这些记录在上次查询时未考虑。

我怎样才能获得所需的记录。 建议我对我的问题有任何疑问。

先谢谢。

0 个答案:

没有答案