![]() | |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
My question is: How can I write a query to find the most frequent item in a column of a relation? Say I have a relation about several guys knowing a certain number of foregin languages. How can I project the guy who speaks the max number of foreign languages? person foreign language John Spanish Brian Spanish Charlie Spanish John Japanese Brian French Brian German Obviously Brian speaks three foreign languages, more than anyone else in the relation table does. How can I project Brian with a relational-algebra statement, perhaps with the help with the aggregate functions like max, min, count, etc? |
#3
| |||
| |||
|
|
John wrote: My question is: How can I write a query to find the most frequent item in a column of a relation? Say I have a relation about several guys knowing a certain number of foregin languages. How can I project the guy who speaks the max number of foreign languages? person foreign language John Spanish Brian Spanish Charlie Spanish John Japanese Brian French Brian German Obviously Brian speaks three foreign languages, more than anyone else in the relation table does. How can I project Brian with a relational-algebra statement, perhaps with the help with the aggregate functions like max, min, count, etc? Assuming table JUNK created as: create table junk (person varchar(18),language varchar(18)) having following rows: select * from junk PERSON LANGUAGE ------------------ ------------------ John Spanish Brian Spanish Charlie Spanish John Japanese Brian French Brian German 6 record(s) selected. query like this is what you are probably trying to achieve: select person, count(language) as Languages from junk group by person PERSON LANGUAGES ------------------ ----------- Brian 3 Charlie 1 John 2 3 record(s) selected. Jan M. Nelken |
#4
| |||
| |||
|
|
How can I project Brian with a relational-algebra statement, perhaps with the help with the aggregate functions like max, min, count, etc? |
#5
| |||
| |||
|
|
Then how do I project "Brian" with the last result set? with a max function? BTW, how can I translante "select person, count(language) as Languages from junk group by person" into relational-algebra? |
#6
| |||
| |||
|
|
Then how do I project "Brian" with the last result set? with a max function? BTW, how can I translante "select person, count(language) as Languages from junk group by person" into relational-algebra? |
#7
| |||
| |||
|
![]() |
| Thread Tools | |
| Display Modes | |
| |