In dire need of help! (1 Viewer)

BlueIshDan

☠
Local time
Today, 12:41
Joined
May 15, 2014
Messages
1,122
My brain is not in any way allowing to me do SQL today. This is the most simple task, but I accept the fact that Mr. Brain says NO and that NO means NO! :banghead:

Could I get some help with creating this query.



Results:
  • mail.id,
  • mail.subject,
  • mail.body,
  • SUM(words.sentiment_score)


TABLES & RELATIONS:

 

Attachments

  • MailDatabaseRelationships.JPG
    MailDatabaseRelationships.JPG
    32 KB · Views: 129

BitsOfBytes

Registered User.
Local time
Today, 11:41
Joined
Apr 14, 2015
Messages
15
Just leave your query as is. Go to the ribbon and under design click 'totals'. Select 'group on' for all of your columns except the one you are trying to sum. Change that grouping option to 'sum'.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 23:41
Joined
May 7, 2009
Messages
19,242
this is an air code:

select mail.id, mail.subject, mail.body, (select sum(sentiment_score) from [words] where [words].id = mail_words.word_id) As SumOfSentiment_Score from mail left join mail_words on mail.id = mail_words.mail_id
 

BlueIshDan

☠
Local time
Today, 12:41
Joined
May 15, 2014
Messages
1,122
Thank you for your guidance, this is the query that worked out for me. =]
Code:
SELECT 
	mail.ID, 
	mail.subject, 
	mail.body, 
	Sum([sentiment_score]*[count]) AS Score

FROM 
	words 
	INNER JOIN (
		mail 
		INNER JOIN mail_words 
		ON mail.ID = mail_words.mail_id) 
	ON words.ID = mail_words.word_id

GROUP BY 
	mail.ID, 
	mail.subject, 
	mail.body;
 

Users who are viewing this thread

Top Bottom