Jump to content

What is the query?

- - - - -

  • Please log in to reply
4 replies to this topic

#1
Tank314

Tank314

    Newbie

  • Members
  • PipPip
  • 10 posts
So I have database with columns "brands" "price" "other stuff"
brands is like volvo, opel and so on. Prices are numbers.
There are several rows with same brand but different prices.
What query do I send to return 1 column with brand names(distinct)
And other column with average price per every brand?

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
it depends a little on the database type, but something like
select avg(price), brands from table group by grands

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
johnhardy009

johnhardy009

    Newbie

  • Members
  • PipPip
  • 14 posts
Queries are essentially powerful Filters. Queries allow you to decide what fields or expressions are to be shown and what information to be sought.
Queries can select records that fit certain criteria. If you had a list of people and had a gender field you could use a query to select just the males or females in the database.

#4
williamlewis

williamlewis

    Newbie

  • Members
  • Pip
  • 2 posts
In this problem you made you should know about the key word "GROUP BY".That mean category column data in to distinct filed. finally use AVG key word to find average. Like wise you can write any query using GROUP BY key word.

SELECT brands,AVG(price) from <your_table_name> GROUP BY brands

For more details you can follow this URL.
<http://www.techyv.com/questions/how-group-data-month-when-using-datetime-column-mysql>

#5
williamlewis

williamlewis

    Newbie

  • Members
  • Pip
  • 2 posts
In this problem you made you should know about the key word "GROUP BY".That mean category column data in to distinct filed. finally use AVG key word to find average. Like wise you can write any query using GROUP BY key word.

SELECT brands,AVG(price) from <your_table_name> GROUP BY brands

For more details you can follow this URL.
<http://www.techyv.com/questions/how-group-data-month-when-using-datetime-column-mysql>




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users