Question :
I have a query that i have to find the DiscountPercent that are the same and not show the rows with the same DiscountPercent. I have tryd this and it brings back the values that are the same
SELECT
ProductName,DiscountPercent
FROM
Products
WHERE
DiscountPercent in (SELECT DiscountPercent
FROM Products
GROUP BY DiscountPercent
HAVING COUNT(*) < 1)
ORDER BY
ProductName;
What i want to accomplish is to bring in the products that don’t have the same discount percentage. I don’t think i am doing this the right way.What is the correct way of doing this?
This is some data in the ProductName and in the DiscountPercentage
ProductName DiscountPercent
Fender Precision 30.00
Fender Stractocaster 30.00
Gibson Les Paul 30.00
Gibson SG 52.00
Hofner Icon 25.00
Ludwig 5-piece 30.00
Rodriguez Cabelle 39.00
Tama 5-piece 15.00
Washburn D10 0.00
Yamaha FG700s 38.00
The Desired result that must use a subquery
ProductName DiscountPercent
Fender Precision 30.00
Gibson SG 52.00
Hofner Icon 25.00
Rodrgiguez Cabelle 39.00
Tama 5-piece 15.00
Washiburn D10 0.00
Yamaha FG700s 38.00
Answer :
SELECT MIN(ProductName), DiscountPercent
FROM Products
GROUP BY DiscountPercent;
You might find the output from this interesting:
SELECT DiscountPercent,
GROUP_CONCAT(ProductName)
FROM Products
GROUP BY DiscountPercent;