1

我目前正在使用 SQLite,我对这个查询感到害怕

    SELECT Cur.Name, SUM(Cur.Added+Cur.Removed) AS Lines, COUNT(DISTINCT(Cur.Author)) AS authCurrent,
       ( SELECT COUNT(DISTINCT(Author)) 
         FROM Change
         WHERE Extencion = "java" AND
             Date >= date('2012-04-08') AND
             Date < date('2012-04-15')
         ) AS totCurrent
    FROM 
       Change AS Cur,
       ( SELECT a.Name, COUNT(DISTICT(a.Author)) AS authLast
         FROM Change AS a
         WHERE a.Extencion = "java" AND
           a.Date >= date('2012-04-08') AND
           a.Date < date('2012-04-15')
       GROUP BY a.Name ) AS Previous
    WHERE
       Previous.Name = Cur.Name
       Cur.Extencion = "java" AND
       Cur.Date >= date('2012-04-15') AND
       Cur.Date < date('2012-04-22')
   GROUP BY Cur.Name

它说“查询错误:靠近“Cur”:语法错误无法执行语句”我不知道,是不是因为SQLite不支持嵌套查询而导致查询不可执行?

无论如何,表更改具有以下形式

      Author | Path | Extencion | Name | Date | Added | Removed
4

1 回答 1

1

看来您DISTINCT在这一行拼写错误:

COUNT(DISTICT(a.Author)) AS authLast  -- change to DISTINCT

您是否也以这种方式尝试过查询:

SELECT Cur.Name, 
  SUM(Cur.Added+Cur.Removed) AS Lines, 
  COUNT(DISTINCT(Cur.Author)) AS authCurrent,
  Previous.authLast AS totCurrent
FROM Change AS Cur
LEFT JOIN 
( 
  SELECT a.Name, COUNT(DISTINCT(a.Author)) AS authLast
  FROM Change AS a
  WHERE a.Extencion = "java" AND
    a.Date >= date('2012-04-08') AND
    a.Date < date('2012-04-15')
  GROUP BY a.Name
) AS Previous
  ON Previous.Name = Cur.Name
WHERE 
       Cur.Extencion = "java" AND
       Cur.Date >= date('2012-04-15') AND
       Cur.Date < date('2012-04-22')
GROUP BY Cur.Name, Previous.authLast
于 2013-01-14T10:10:45.977 回答