简体   繁体   中英

Using count in oracle sql developer

I'm using oracle sql developer and I can't get this query to function. It's telling me its not a single group function. Please help.

SELECT LGBRAND.BRAND_NAME, LGPRODUCT.PROD_DESCRIPT,
    COUNT (LGPRODUCT.PROD_DESCRIPT) AS "NUMPRODUCTS"
FROM LGBRAND, LGPRODUCT
ORDER BY LGBRAND.BRAND_NAME;

What I'm trying to accomplish is to get the total different products grouped by each brand name.

when using aggregate functions you need to use group by clause

All aggregate functions like avg, count,sum needs to be used along with a group by function. If you dont use a group by clause, you are performing the function on all the rows of the table.

  SELECT LGBRAND.BRAND_NAME,
           LGPRODUCT.PROD_DESCRIPT,
           COUNT (LGPRODUCT.PROD_DESCRIPT) AS "NUMPRODUCTS"
    FROM LGBRAND, LGPRODUCT,
    GROUP BY LGBRAND.BRAND;

您需要使用GROUP BY子句。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM