0
select abc.mnth as mnth,sum(abc.info) as info from (select aaa.mnth as mnth, aaa.info as info from ((select ontime.mnth as mnth, ontime.info as info from (SELECT OnTimeRecords.mnth as mnth , round(((OnTimeRecords.count/completed.count)*100),2) as info
  from (SELECT DATE_FORMAT(t.dtDelivery,'%V %X') as mnth, count(*) as count FROM table1 t
     WHERE fCompleted = 1
     AND t.fStatus = 1
     AND t.dtDelivery >= '2013-01-01 00:00:00'
     AND t.dtDelivery <= '2013-12-28 23:59:59'
     AND FIND_IN_SET(t.sProjectCode,'All,pj1,pj2,hhfgh,tewrtert,dfgdgdf,Project Code,null,tyuire,dfgdfgdf,[select]') > 0
     AND t.dtDelivery  <= t.dtDeliveryDue
     group by DATE_FORMAT(t.dtDelivery,'%V %X')
     order by DATE_FORMAT(t.dtDelivery,'%V %X')) as completed
  Inner join (SELECT DATE_FORMAT(t.dtDelivery,'%V %X') as mnth, count(*) as count FROM table1 t
     WHERE fCompleted = 1
     AND t.fStatus = 1
     AND FIND_IN_SET(t.sProjectCode,'All,pj1,pj2,hhfgh,tewrtert,dfgdgdf,Project Code,null,tyuire,dfgdfgdf,[select]') > 0
     AND t.dtDelivery >= '2013-01-01 00:00:00'
     AND t.dtDelivery <= '2013-12-28 23:59:59'
     AND t.dtDelivery  <= t.dtDeliveryDue
     group by DATE_FORMAT(t.dtDelivery,'%V %X')
     order by DATE_FORMAT(t.dtDelivery,'%V %X')) as OnTimeRecords on OnTimeRecords.mnth = completed.mnth) as ontime)
union all
(select monthdates.mnth as mnth, monthdates.info as info from
    ((select  distinct(DATE_FORMAT(aDate,'%V %X')) as mnth ,0 as info  from (
    select @maxDate - interval (a.a+(10*b.a)+(100*c.a)+(1000*d.a)) day aDate from
    (select 0 as a union all select 1 union all select 2 union all select 3
     union all select 4 union all select 5 union all select 6 union all
     select 7 union all select 8 union all select 9) a, /*10 day range*/
    (select 0 as a union all select 1 union all select 2 union all select 3
     union all select 4 union all select 5 union all select 6 union all
     select 7 union all select 8 union all select 9) b, /*100 day range*/
    (select 0 as a union all select 1 union all select 2 union all select 3
     union all select 4 union all select 5 union all select 6 union all
     select 7 union all select 8 union all select 9) c, /*1000 day range*/
    (select 0 as a union all select 1 union all select 2 union all select 3
     union all select 4 union all select 5 union all select 6 union all
     select 7 union all select 8 union all select 9) d, /*10000 day range*/
    (select @minDate :='2013-01-01 00:00:00', @maxDate :='2013-12-28 23:59:59') e
  ) f
  where aDate between @minDate and @maxDate
  order by aDate asc
)) as monthdates) ) as aaa
order by aaa.mnth desc) as abc
group by abc.mnth
order by  STR_TO_DATE (abc.mnth,'%V %X');

開始日と終了日に基づいてレポートを生成したい。週ごとのレポートが欲しいです。クエリ結果は次のようになります。

week                     info
02 2013          0
06 2013         100
01 2013          0
05 2013          0
53 2012          0
04 2013          0
08 2013         100
03 2013          0
07 2013         100

以下のような結果が欲しい

week                    info
53 2012         0
01 2013         0
02 2013         0
03 2013         0
04 2013         0
05 2013         0
06 2013        100
07 2013        100
08 2013        100
4

1 に答える 1

0

このクエリは非常に複雑で、ORDER BYすべての疑似テーブルselectステートメントに存在するようです。

すべてのsを削除しORDER BYて結果を確認し、(結果が満足のいくものであると仮定して)ORDER BY最後に1つを適用してみます。おそらくORDER BY abc.mnthこれは日付のようで、日付順にしたいと思います。

于 2013-02-14T15:50:57.670 に答える