我在SQL server中有以下查询。现在,数据库正在使用SQLite在移动设备上使用。有人可以帮助使用可在SQLite中运行的等效文件吗?
Select DISTINCT TblSites.Customer, TblSites.Digit, Count(TblContractTasks.TaskNumber) OVER (PARTITION BY TblSites.Digit) As TaskCount
FROM TblContractTasks INNER Join (TblSites INNER Join TblContractDetails On TblSites.Digit = TblContractDetails.SiteDigit) On TblContractTasks.ContractNumber = TblContractDetails.ContractNumber
WHERE TblSites.Consultant='xx'
ORDER BY TblSites.Digit
表:
Customer Site TaskNumber
------------------------
Ca Sa 100
Ca Sa 101
Cb Sb 88
Ca Sa 103
查询结果:
Customer Site TaskCount
-----------------------
Ca Sa 3
Cb Sb 1
答案 0 :(得分:1)
您是否只是在寻找GROUP BY
?
SELECT s.Customer, s.Digit, COUNT(*) As TaskCount
FROM TblSites s INNER JOIN
TblContractDetails cd
ON s.Digit = cd.SiteDigit INNER JOIN
TblContractTasks t
ON t.ContractNumber = cd.ContractNumber
WHERE s.Consultant = 'xx'
GROUP BY s.Customer, s.Digit
ORDER BY s.Digit;
这将返回您指定的数据的结果集。它似乎比从SELECT DISTINCT
和您的COUNT() OVER
获得的结果集更实用。