I am trying to filter out all positive averages by using the line
HAVING AVG(blurt_analysis.sentiment) < 0
however for an unexpected reason this line isn't doing as expected and in fact is making my query return nothing and im having a hard time figuring out why my query looks like
SELECT topic.id,topic.description,blurt.location,count(blurt.blurtid)as 'number of blurts',AVG(blurt_analysis.sentiment) as avgSentiment
FROM topic, blurt_analysis,blurt
WHERE topic.id=blurt_analysis.topicid AND blurt.blurtid = blurt_analysis.blurtid AND blurt.email = blurt_analysis.email
group by blurt.location,topic.id
HAVING AVG(blurt_analysis.sentiment) < 0
the return looks like this without the having line and is empty with the line
1 shoes California 2 2.5000
2 speaker California 3 1.3333
3 bats California 3 1.0000
4 hoodies California 2 -0.5000
5 caps California 1 -2.0000
6 pens California 2 0.0000
7 games California 4 1.2500
1 shoes Colarado 1 1.0000
2 speaker Colarado 3 1.6667
3 bats Colarado 1 1.0000
5 caps Colarado 1 3.0000
7 games Colarado 1 1.0000
with the first column being topicid the second being topic description the third being blurt location the 4th being the number of blurts and the 5th being avg sentiment(what im trying to filter positive numbers from)
UPDATE I still have not managed to figure out why the query doesnt work with having but I managed to filter positive numbers with another add making my sql look like
SELECT topic.id,topic.description,blurt.location,count(blurt.blurtid)as 'number of blurts',AVG(blurt_analysis.sentiment) as avgSentiment
FROM topic, blurt_analysis,blurt
WHERE topic.id=blurt_analysis.topicid AND blurt.blurtid = blurt_analysis.blurtid AND blurt.email = blurt_analysis.email AND blurt_analysis.sentiment <0
group by blurt.location,topic.id,topic.description