# Use count() in relational algebra

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))$ ?

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

$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}))$