interface person
( extent Persons )
{ attribute String name;
  attribute Short age;
};


interface department
( extent Departments )
{ attribute String name;
  attribute String address;
};


interface employee:person
( extent Employees )
{ attribute set<person> children;
  attribute department dept;
  attribute employee manager;
};



department Research := department("Research","Beaverton");

department IS := department("IS","Hillsboro");

department CSE := department("CSE","Portland");

department EE := department("EE","Aloha");

person kid1 := person("nick",25);

person kid2 := person("jim",20);

person kid3 := person("jennifer",8);

employee Smith := employee("Smith",35,set(kid1,kid2),Research,null);

employee Tim := employee("Tim",40,set(kid3),CSE,null);

employee Jones := employee("Jones",40,set(),Research,Smith);

employee Leo := employee("Leo",35,set(),CSE,Tim);



Leo.dept.name;


Leo.dept.name = Tim.dept.name;


struct( A: 1, B: "q" );


if (Leo.dept.name = "CSE")
then Leo.age+8
else Leo.age+1;


set(1,2,3) union set(8);


list(CSE.name,IS.name);


count(Employees);


select e.name
from e in Employees;


select p.name
from p in Persons;


select e.age
from e in Employees,
     d in Departments
where e.name = d.name;


(select e.name
 from e in Employees)
union
(select d.name
 from d in Departments);


(select e.name
 from e in Employees)
intersect
(select d.name
 from d in Departments);


select struct( E: e.name, D: e.dept.name )
from e in Employees;


sum( select e.age
     from e in Employees );


for all e in Employees: e.age>10;


exists e in Employees: e.age>38;


select c.name
from e in Employees,
     c in e.children
where e.name = "Smith"
  and c.age > 18;


select distinct struct( D: d.name,
			E: ( select e.name
			     from e in Employees
			    where e.dept = d ) )
from d in Departments;


select struct( A: (select c.name from c in e.children), 
	       B: (select m.name from m in e.manager.children) )
from e in Employees;


flatten(select e.children from e in Employees);


select struct( E: e.name, D: e.dept.name )
from e in Employees
where e.age>37;


select distinct struct( E: e.name,
			M: ( select c.name
			     from c in e.children
			    where c.age > 18 ) )
from e in Employees
where e.name = "Smith";


select c.name
from e in Employees,
     c in e.children
where e.age-c.age > 25;


select distinct struct( E: e.name,
			C: e.manager.name,
			M: ( select c.name
			       from c in e.children
			      where for all d in e.manager.children: c.age > d.age ) )
from e in Employees;


select distinct struct( E: e.name,
			C: ( select u.name
			       from u in (select a from a in Employees where a.name = "Smith")
			      where u.dept = e.dept),
			M: ( select c.name
			       from c in e.children
			      where for all d in e.manager.children: c.age > d.age ) )
from e in Employees;


select struct( E: e.name, D: e.dept.name, N: e.dept.address )
from e in Employees
where e.age>37 and e.dept.name="CSE";


group e in Employees by ( dname: e.dept.name );


group e in Employees
   by ( dname: e.dept.name )
 with ( a: partition );
