Jump to content

What's wrong SQL

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Tank314

Tank314

    Newbie

  • Members
  • PipPip
  • 10 posts
SELECT märke, avg( pris ) 
FROM bil
WHERE märke =  "SAAB"
OR märke =  "Volvo"

It gives me average price only for Volvo but not for SAAB.

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Better add
GROUP BY märke 
to your query.

#3
ace26

ace26

    Newbie

  • Members
  • Pip
  • 3 posts

Tank314 said:

SELECT märke, avg( pris ) 

FROM bil

WHERE märke =  "SAAB"

OR märke =  "Volvo"

It gives me average price only for Volvo but not for SAAB.

Replace the "OR" in the WHERE clause with an "AND" if you want the average of both combined.

#4
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
Replacing OR with AND would result in no results.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users