我使用MS Access创建了此查询:
SELECT
Abonentai.vardas AS name,
Abonentai.pavarde AS name1,
Abonentai.email AS email,
Abonentai.Telefonas AS phone1,
Abonentai.[Gimimo metai] AS birthdate,
"" AS phone2,
"" AS name2,
Last(Abonentai.Suma) AS paycost,
Abonentai.vardas & " " & Abonentai.pavarde AS fullname,
Last(AbonentaiD.Planas) AS Abonement_Code,
Last(AbonentaiD.Nuo) AS Abonement_StartDate,
Last(AbonentaiD.Iki) AS Abonement_ExpDate,
Last(AbonentaiD.Kartai) - (SELECT COUNT(StatistikaID) FROM Statistika WHERE Statistika.AbonentasID = Abonentai.AbonentasID AND Statistika.AtvykimoData > (SELECT Last(AbonentaiD.Nuo) FROM AbonentaiD WHERE AbonentaiD.AbonentasID = Statistika.AbonentasID)) AS MAXQUANTVISIT,
Abonentai.ANr AS CARDNO,
"22" AS CARDTYPE,
"" AS INFO
FROM Abonentai
LEFT JOIN AbonentaiD ON Abonentai.AbonentasID = AbonentaiD.AbonentasID
WHERE
(((AbonentaiD.Iki)>Date())) AND (((AbonentaiD.Kartai) Is Null)) OR (((AbonentaiD.Kartai) Is Not Null) AND ((Abonentai.GaliojimoData)>Date()))
GROUP BY
Abonentai.vardas,
Abonentai.pavarde,
Abonentai.email,
Abonentai.Telefonas,
Abonentai.[Gimimo metai],
Abonentai.vardas & " " & Abonentai.pavarde,
Abonentai.ANr,
Abonentai.AbonentasID,
Abonentai.RegistracijosData
HAVING
Last(AbonentaiD.Kartai) - (SELECT COUNT(StatistikaID) FROM Statistika WHERE Statistika.AbonentasID = Abonentai.AbonentasID AND Statistika.AtvykimoData > (SELECT Last(AbonentaiD.Nuo) FROM AbonentaiD WHERE AbonentaiD.AbonentasID = Statistika.AbonentasID)) > 0
OR
Last(AbonentaiD.Kartai) - (SELECT COUNT(StatistikaID) FROM Statistika WHERE Statistika.AbonentasID = Abonentai.AbonentasID AND Statistika.AtvykimoData > (SELECT Last(AbonentaiD.Nuo) FROM AbonentaiD WHERE AbonentaiD.AbonentasID = Statistika.AbonentasID)) IS NULL
;
但是需要很多时间才能完成它。有没有办法减少执行时间?我需要我选择的每一个vaue。