我从5列中提取数据,其中有两个连接,我需要按其中一列进行分组。但是,当我尝试在最后分组时,我收到了错误。我需要某种子查询吗?
SELECT
TERRITORY_T.TERRITORYID,
TERRITORY_T.TERRITORYNAME,
CUSTOMER_T.CUSTOMERID,
ORDER_T.ORDERID,
PRODUCT_T.PRODUCTID
FROM
TERRITORY_T,
CUSTOMER_T,
ORDER_T,
PRODUCT_T,
DOESBUSINESSIN_T
WHERE
TERRITORY_T.TERRITORYID = DOESBUSINESSIN_T.TERRITORYID
AND CUSTOMER_T.CUSTOMERID = DOESBUSINESSIN_T.CUSTOMERID
GROUP BY
ORDERID
ORDER BY
TERRITORYID DESC,
CUSTOMERID
客户表和订单表都有CustomerID。我是否需要先查询它们,使用group by,然后与其他表连接?