CSE594
Database Management Systems
University of Washington
Fall 1999
Some OQL Queries
17
BestEmp
BestEmp.name
Employees union People
People.name
select P.name from P in People
where P.age > 10
select P.name, P.age from P in People
select struct (name: P.name, age: P.age) from P in People
select Emp) E).sal from E in People
select ((Emp) E).sal from E in People where E in Employees
select ((Emp) E).sal from E in People where E->isEmp
exists P in People: P.age > 15
sort P in People by P.name
select x.name from x in (sort P in People by P.name)
select P.DOB.year from P in People3
BestEmp
: result is an OID*BestEmp
select E from E in Employees where E = BestEmp
select E from E in Employees where *E = *BestEmp
select E from E in Employees where E->deep_equal (BestEmp)
Companies [0:1]
listtoset (Companies)
select D.emps from D in Departments
avg (select E.age from E in Employees)
group E in Employees by (age: E.age)
To add average salary for each group, append:
with (avgsal: avg (select P.sal from P in partition))
Note that there is no need for a "having" clause in OQL (why not??)
select struct (dname: D.name, ages: select E.age from E in D.emps)
from D in Departments
select struct (dname: D.name, eage: E.age)
from D in Departments, E in D.emps
select struct (pname: P.name, page: P.age, chairname: D.chair.name)
from P in People, D in Departments
where P.name = D.name