-2

I'm stuck with relational algebra.

I mean, how can I express functions like "SUM(), COUNT()," etc in RA?

Thanks, any help will be kindly appreciated

philipxy
  • 14,867
  • 6
  • 39
  • 83
ubi_v
  • 92
  • 2
  • 8
  • To clarify: when you ask `etc in RA`, are you asking `etc in RA **notation**`? That's what I assumed in my answer below. If so, adding that word "notation", to the question, would probably get the question OFF of "on hold" status. You could also add the word "notation" to the question title. – Doug_Ivison Feb 15 '14 at 11:43
  • There are many RAs (relational algebras). They differ in operators & even what a relation is. Give a reference and/or definition for yours. Eg textbook name, edition & page. – philipxy Oct 10 '19 at 00:08

2 Answers2

3

To start, you simply have to know that SUM and COUNT are called aggregate functions. Then, just google "relational algebra for aggregate functions".

I don't know how to subscript/superscript on Stack Overflow, but this wikipedia entry has an example at the end of the paragraph. (You'll see GMax(Balance)(Account).)

Also promising: go to this link, and search the page for "Aggregate"... you'll see Fsum(salary)(E) with subscripts.

Doug_Ivison
  • 778
  • 7
  • 17
1

something like this?

SQLFiddle example

what cannot you understand? be more specific please.

You can find more details in your DBMS documentation

Or visit the wiki

Basically aggregate functions will make some kind of "cumulative" operation over a set of rows and usidng one column to (SUM, AVERAGE, etc) based on one or more "key" columns.

Example: You have a dataset containing demographic data from all cities of the nation, it happens to have a population count and a region identity column. You can use it to create a report of total population by region.

jean
  • 4,159
  • 4
  • 31
  • 52