2
$\begingroup$

Person(name, phone)
Mike 456-789
Mike 123-456
John 230-785
$\dots \dots$

How to get those people who have more than one phone numbers with relational algebra? This sounds simple, but I am frustrated with all materials that I've learned.

Is it correct syntax to use count() like $\pi_{name}(\sigma_{count(phone)>2}(Person))$ ?

$\endgroup$
  • 1
    $\begingroup$ the relation will be stored how? the 2 phone numbers will it be stored on the same tuple? or in different ones? $\endgroup$ – Haris Sep 11 '14 at 18:35
  • $\begingroup$ different. I've edited the OP to clarify this. $\endgroup$ – canoe Sep 12 '14 at 0:47
7
$\begingroup$

A syntax of aggregate operation in relational-algebra (according to [1]) is as follows :

$G_1,G_2,...,G_n \hspace{2 mm}\textbf{g}\hspace{2 mm} F_1(A_1),F_2(A_2),...,F_m(A_m)(E)$

where $E$ is any relational-algebra expression; $G_1,G_2,...,G_n$ constitute a list of attributes on which to group; each $F_i$ is an aggregate function; and each $A_i$ is an attribute name.

Thus your query would look like : $\pi_{name}(\sigma_{phone>1}(name\hspace{2 mm}\textbf{g}\hspace{2 mm} count (phone)( Person)\hspace{2 mm}))$

[1] A. Silberschatz, H. Korth, S. Sudarshan, Database System Concepts, 5th Edition

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.