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
Post a Comment