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 > How to do this SELECT statement

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-06-09, 01:59
cy163 cy163 is offline
Registered User
 
Join Date: Apr 2007
Posts: 127
How to do this SELECT statement

Hello ALL.

I have a table shown below. It contains words from 3 documents. I would like to know word matching info between two document.Specifically, I would like to know the sum of occurrence frequencies of matching words, e.g. Doc1 and Doc2 have only one matching on 'English', and the sum of frequencies is 1+2=3.

Thanks

Code:
TABLE 

DocID  Word        Freq 
1      English      1 
1      Lesson      2 
1      Work        2 
1      Training    2 

2      English      2 
2      Have        2 
2      Class        2 
2      Student      3 


3      Lesson      3 
3      Chinese      2 
3      Chair        2
Reply With Quote
  #2 (permalink)  
Old 03-06-09, 02:57
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
have a look at the MySQL manual for the following SQL clauses/terms
count
sum
group by

rather than provide the SQL I'd suggest doing it this waa round so you start to understand how SQL works
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 03-06-09, 05:27
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
healdem, i guess you aren't familiar with cy163's previous posts

he's ~way~ beyond needing to look things up in da manual

he's been working on this app for months and months

where he needs help is understanding his data so that he can formulate the queries
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #4 (permalink)  
Old 03-06-09, 16:56
aradapilot aradapilot is offline
Registered User
 
Join Date: Feb 2009
Location: Rutherford, NJ
Posts: 9
select word, SUM(freq)
from table
group by word


thatll give you a list of all words with the total number of times they were used.
Reply With Quote
  #5 (permalink)  
Old 03-07-09, 01:50
bklr bklr is offline
Registered User
 
Join Date: Dec 2008
Posts: 133
try this once
Code:
declare @tbl table(DocID int, Word  varchar(23),Freq int)
insert into @tbl select 
1 ,     'English',      1 
insert into @tbl select 
1,      'Lesson',      2 
insert into @tbl select 
1 ,     'Work',      2 
insert into @tbl select 
1,      'Training',      2 
insert into @tbl select 
2,      'English',      2 
insert into @tbl select 
2,      'Have',        2 
insert into @tbl select 
3,      'Lesson',      3 
insert into @tbl select 
3 ,    'Chinese',      2 

select s.word, SUM(s.freq)as freq
from @tbl s inner join @tbl t on t.word = s.word and t.docid <> s.docid
where s.docid in (1,2) and t.docid in (1,2)
group by s.word
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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