仅显示子查询中的 1 列:列出 bran_name whos avg price is >= 3 and also have at least 2 distinct products

display only 1 column from the subquery : list the bran_name whos avg price is >= 3 and also have at least 2 distinct products

这是我的查询:

select avg(p2.price), p2.brand_name, count(distinct p2.product_id) 
count_of_products
from product p2
group by p2.brand_name
having count(distinct p2.product_id) >= 2 and avg(p2.price) > 3

但我只需要在最终查询中显示 band_name。 我试过这个:

select p1.brand_name from product p1,
(select avg(p2.price), p2.brand_name, count(distinct p2.product_id) 
count_of_products
from product p2
group by p2.brand_name
having count(distinct p2.product_id) >= 2 ) p2 and and avg(p2.price) > 3
where 
p1.brand_name = p2.brand_name

但它给了我以下错误:

>[Error] Script lines: 3-9 --------------------------
 No column name was specified for column 1 of 'p2'.

but I need to display only band_name in the final query

所以只需从 select 子句中删除其他列:

select brand_name
from product
group by brand_name
having count(distinct product_id) >= 2 and avg(price) > 3