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$
0

1 Answer 1

9
$\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$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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