If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Dual HAVING on AS

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-13-10, 13:18
Aknot Aknot is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
Angry Dual HAVING on AS

Hi all, new here...

I have this, working and is fast.

PHP Code:
SELECT movie.idmovie.titlemovie.cat_1,
movie.prod_yearmovie.director_1movie.imagevote.movieid,
ROUND(SUM(vote.vote)/COUNT(vote.vote),2) AS Average
FROM movie
vote WHERE vote.movieid=movie.id
AND movie.image != 'missing.png'
AND movie.prod_year >= '2000'
AND movie.image IS NOT NULL GROUP BY vote.movieid
HAVING Average 
>= '8'
ORDER BY RAND()
LIMIT 5
Now I want to add something like this. I want to show the movies with ten votes or more. Can't get it to work

PHP Code:
SELECT movie.idmovie.titlemovie.cat_1movie.prod_yearmovie.director_1movie.imagevote.movieid,
ROUND(SUM(vote.vote)/COUNT(vote.vote),2) AS Average,
COUNT(vote.vote),2) AS Votes
FROM movie
vote
WHERE vote
.movieid=movie.id
AND movie.image != 'missing.png'
AND movie.prod_year >= '2000'
AND movie.image IS NOT NULL
GROUP BY vote
.movieid
HAVING Average 
>= '8'
HAVING Votes >= '10'
ORDER BY RAND()
LIMIT 5
Anyone have an idea?

Best regards
Reply With Quote
  #2 (permalink)  
Old 02-13-10, 14:58
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,084
use ANDs and ORs to make compound HAVING conditions, the same way that you use ANDs and ORs to make compound WHERE conditions

Code:
HAVING Average >= 8 
   AND Votes >= 10
note: use numeric constants when comparing with numeric values (i.e. don't put quotes around them)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-13-10, 15:46
Aknot Aknot is offline
Registered User
 
Join Date: Feb 2010
Posts: 2
Worx perfect! I did try AND, but like 'AND HAVING >= 10', using HAVING again

Thanks alot
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On