访问:简化sql-query:多个IIF

时间:2013-10-31 12:49:00

标签: sql ms-access ms-office

我有一个带有日期列的表和一个这样的列:

Column
01-00-00-00
01-02-00-00
03-06-00-00
05-13-00-00
....

我想做什么:了解每天以“01”,“02”,“03”开始的条目数量。  因此,我需要先减去前2个字符,计算它们并按日期分组。

我的代码运行正常,但需要很长时间。您对更简单的查询有什么想法吗?

    SELECT
      Date,
      sum(IIF(Platz='03',1,0)) as Gang_03,
      sum(IIF(Platz='04',1,0)) as Gang_04,
      sum(IIF(Platz='05',1,0)) as Gang_05,
      sum(IIF(Platz='06',1,0)) as Gang_06,
      sum(IIF(Platz='07',1,0)) as Gang_07,
      sum(IIF(Platz='08',1,0)) as Gang_08,
      sum(IIF(Platz='09',1,0)) as Gang_09,
      sum(IIF(Platz='10',1,0)) as Gang_10,
      sum(IIF(Platz='11',1,0)) as Gang_11,
      sum(IIF(Platz='12',1,0)) as Gang_12,
      sum(IIF(Platz='13',1,0)) as Gang_13,
      sum(IIF(Platz='14',1,0)) as Gang_14,
      sum(IIF(Platz='15',1,0)) as Gang_15,
      sum(IIF(Platz='16',1,0)) as Gang_16,
      sum(IIF(Platz='17',1,0)) as Gang_17,
      sum(IIF(Platz='18',1,0)) as Gang_18,
      sum(IIF(Platz='19',1,0)) as Gang_19,
      sum(IIF(Platz='20',1,0)) as Gang_20
    FROM
      (
      SELECT
            time_neu as Date,
            LEFT(Platz_von,2) as Platz
      FROM
            00_Gesamt_Pickauf
      )
    GROUP BY
      Date

0 个答案:

没有答案