0

I am fairly new to SQL statements and I am trying to print units sold from a database. Under the units sold column it will not print the number it will just print "Units Sold". Any help would be greatly appreciated. Here is my code:

SELECT brand_name, brand_type, Round(avgprice,2) AS "Average Price", "Units Sold"
FROM lgbrand b 
JOIN (
   SELECT brand_id, Avg(prod_price) AS avgprice
   FROM lgproduct
   GROUP BY brand_id
) sub1 ON b.brand_id = sub1.brand_id
JOIN (
   SELECT brand_id, Sum(line_qty) AS "Units Sold" 
   FROM lgproduct p 
   JOIN lgline l ON p.prod_sku = l.prod_sku
   GROUP BY brand_id
) sub2 ON b.brand_id = sub2.brand_id

ORDER BY brand_name;
Hogan
  • 69,564
  • 10
  • 76
  • 117
  • Possible duplicate of [When to use single quotes, double quotes, and backticks in MySQL](http://stackoverflow.com/questions/11321491/when-to-use-single-quotes-double-quotes-and-backticks-in-mysql) – Paul Spiegel Mar 31 '17 at 18:59

1 Answers1

0

Try this:

SELECT brand_name, brand_type, Round(avgprice,2) AS "Average Price",  Units_Sold
FROM lgbrand b 
JOIN (
   SELECT brand_id, Avg(prod_price) AS avgprice
   FROM lgproduct
   GROUP BY brand_id
) sub1 ON b.brand_id = sub1.brand_id
JOIN (
   SELECT brand_id, Sum(line_qty) AS Units_Sold
   FROM lgproduct p 
   JOIN lgline l ON p.prod_sku = l.prod_sku
   GROUP BY brand_id
) sub2 ON b.brand_id = sub2.brand_id

ORDER BY brand_name;
Hogan
  • 69,564
  • 10
  • 76
  • 117
  • It got the column to not say units sold anymore, but the values are not correct, first one is suppose to be 3753 and first one with that code is 6062 – Ryan Blanchard Mar 31 '17 at 19:03
  • @RyanBlanchard you would have to explain a lot more about your data model sample values and expected results before I could help you with that. – Hogan Mar 31 '17 at 19:32