SQLite3connection: near "(":Systax error in Lazarus : I have a Sql deviation statement, but I found the error when running. I have researched many related topics to come up with solutions, but I have not yet solved it. SQLite3connection: near "(":Systax error 
I hope to get help from everyone.
-----------------------------------
strSQL:='SELECT Mathang.Stt,Mathang.Mahang, Mathang.Tenhang,SUM(CASE WHEN Xuatnhap.Loaiphieu="N" AND SQLQuery1.FieldByName("Ngay").asString <= StrToDate(Edit1.Text) THEN Xuatnhap.Soluong  ELSE 0  END) AS Tongnhap,SUM(CASE WHEN Xuatnhap.Loaiphieu="X" AND SQLQuery1.FieldByName("Ngay").asString <= StrToDate(Edit1.Text) THEN Xuatnhap.Soluong   ELSE 0  END) AS Tongxuat,SUM(CASE WHEN Xuatnhap.Loaiphieu="N" AND SQLQuery1.FieldByName("Ngay").asString <= StrToDate(Edit1.Text) THEN Xuatnhap.Soluong ELSE 0 END) - SUM(CASE WHEN Xuatnhap.Loaiphieu="X" AND SQLQuery1.FieldByName("Ngay").asString <= StrToDate(Edit1.Text) THEN Xuatnhap.Soluong ELSE 0  END) AS Tongton FROM Mathang INNER JOIN Xuatnhap ON Mathang.Mahang=Xuatnhap.Mahang GROUP BY  Mathang.Stt,Mathang.Mahang, Mathang.Tenhang';