0

Hi,
I am trying to understand MySQL as i am new to this and i have a few queries I am having problems with and I was wondering if anyone can help me with it.. How would you solve this problem using the Select, from, where etc commands.
For example if you were to Find out what the average cost of all the books in a book table is, how would you write it.. and also how to find out which book cost the MOST in a book table, how would you write it.. I have tried to write what i have thought but its not giving me any answer at all.. I am using MySQL query.. Thank you so much in advance for your help

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by dami06
0

Hi,
I am trying to understand MySQL as i am new to this and i have a few queries I am having problems with and I was wondering if anyone can help me with it.. How would you solve this problem using the Select, from, where etc commands.
For example if you were to Find out what the average cost of all the books in a book table is, how would you write it.. and also how to find out which book cost the MOST in a book table, how would you write it.. I have tried to write what i have thought but its not giving me any answer at all.. I am using MySQL query.. Thank you so much in advance for your help

You should be using the avg and max functions.

So to get the average price

select avg(price) from books;

or the most expensive

select title, max(price) from books group by title order by max desc

/you may need to alter these slightly for mysql - i use postgresql these days

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.