sql server - SQL Complex Select - Trouble forming query -


i have 3 tables, customers, sales , products.

sales links customerid productid , has salesprice.

select products.category, avg(saleprice) sales  inner join products on products.productid = sales.productid group products.category 

this lets me see average price sales category. however, want include customers have more 3 sales records or more in db.

i not sure best way, or way, go this. ideas?

you haven't mentioned customer data anywhere i'll assume it's in sales table

you need filter , restrict sales table first customers more 3 sales, join product category , average across categories

select     products.category, avg(saleprice)     (select productid, saleprice sales group customerid having count(*) > 3) s     inner join     products on products.productid = s.productid group     products.category 

Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -