简体   繁体   中英

Do not select grouped items in MySQL

Supposing that I have the following SQL query:

SELECT items, COUNT(customers)
FROM sales
GROUP BY items
HAVING COUNT(customers) > 1;

Is there somehow to do this operation and query only the item column?

I don't want to include the count of customers in my result, and I can't use as an aggregation for WHERE

SELECT items
FROM sales
WHERE COUNT(customers) > 1;

Of course that this query above will throw me an error, because I'm using an aggregation inside WHERE and that's not possible.

You can just remove the COUNT() :

SELECT items
FROM sales
GROUP BY items
HAVING COUNT(customers) > 1;

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