这是我的业务报告,我只需要为ORDER BY创建一个索引。 但是,group by是基于来自不同表的金额和成本的SUM,那么我该如何创建索引呢?
SELECT
TECHNICAL.TEMPLOYEE_ID,CONSULTANT.EMP_NAME,
SUM(SERVICES_PERFORMED.SP_AMOUNT * SERVICE.SER_COST) AS TotalCost
FROM SERVICES_PERFORMED,TECHNICAL,CONSULTANT,SERVICE
WHERE TECHNICAL.TEMPLOYEE_ID = SERVICES_PERFORMED.TEMPLOYEE_ID AND
TECHNICAL.TEMPLOYEE_ID = CONSULTANT.EMPLOYEE_ID AND
SERVICES_PERFORMED.SERVICE_ID = SERVICE.SERVICE_ID
GROUP BY TECHNICAL.TEMPLOYEE_ID,CONSULTANT.EMP_NAME
ORDER BY TotalCost DESC;
这是我想到的查询:
CREATE INDEX TCINDX ON SERVICES_PERFORMED,SERVICE(TotalCost);
但这是不正确的。