sql server - SQL INNER JOIN - Column name in join is also in select *error* -


i'm still pretty new sql , having issues. using variation of classic northwind database. using microsoft sql server management studio.

here problem:

/* join products , productvendors display product, product number, average wholesale price, , average retail price. */ 

here's i've got:

select products.productnumber [product number],        cast(avg(wholesaleprice) decimal (8,2)) [average wholesale price],        cast(avg(retailprice) decimal (8,2))  [average retail price] products inner join productvendors         on products.productnumber = productvendors.productnumber 

here's error get:

msg 8120, level 16, state 1, line 2
column 'products.productnumber' invalid in select list because not contained in either aggregate function or group clause.

exception text self-explanatory. since you're using aggregate functions (avg in case) have group products.productnumber too.

select products.productnumber aa [product number],        cast(avg(wholesaleprice) decimal (8,2)) [average wholesale price],        cast(avg(retailprice) decimal (8,2))  [average retail price] products inner join productvendors      on products.productnumber = productvendors.productnumber group products.productnumber 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -