These are my queries for an assignment. It says that I made a mistake on query 8 and 9... problem is that I don't see any mistakes? Can someone tell me what is wrong?

``````#T1
SELECT * FROM `inventory`;

#T2
SELECT fruitID, sum( quantity ) FROM `inventory` group BY fruitID;

#T3
SELECT `name` FROM `fruit` ORDER BY name;

#T4
SELECT * FROM `fruit` ORDER BY `price` ASC;

#T5
SELECT * FROM `fruit` WHERE `price` > 1.0 ORDER BY price DESC;

#T6
SELECT * FROM `fruit` ORDER BY `fruit`.`price` DESC limit 1;

#T7
select name, sum( quantity ) as
"Total Quantity" from `fruit` as f,
inventory as i
where f.fruitID= i.fruitID
group by i.fruitID
order by sum( quantity ) DESC;

#T8
select sum( quantity ) * (select price from fruit where name like 'apple')
from inventory
where fruitID=(select fruitID from fruit where name like 'apple');

#T9
select price*sum( quantity ) from fruit as f, inventory as i where f.fruitID = i.fruitID group by i.fruitID;

#T10
SELECT * FROM `fruit` where fruitID not in ( select fruitID from inventory );
``````

For query 8, i get this error:

``````First Difference Occurs at: byte 1, line 1
On Line 1 its column 1
Line 1 Wrong: sum( quantity ) * (select price from fruit where name like 'apple')
Line 1 Right: Value of Apples

sdiff side by side difference your output versus solution....
sum( quantity ) * (select price from fruit where name like 'a | Value of Apples
875.00                                | \$875.00
``````

For query 9, i get this error:

``````First Difference Occurs at: byte 1, line 1
On Line 1 its column 1
Line 1 Wrong: price*sum( quantity )
Line 1 Right: name  Value
sdiff side by side difference your output versus solution....
price*sum( quantity )                         | name    Value
875.00                                | apple   875.00
900.00                                | pear    900.00
500.00                                | banana  500.00
``````

DO you need a GROUP BY?

## All 4 Replies

DO you need a GROUP BY?

A `group by`?

Functions such as SUM() are usually accompanied by a GROUP BY clause as you have in statements #T2 and #T7

From the error messages I conclude you should've aliased your resulting columns. Next to that 8 is missing the dollar sign, 9 is missing a column.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.