/* ------------------------------------------------------------------------ */ /* Do not edit this part ---------------------------------------------------*/ /* ------------------------------------------------------------------------ */ :- consult('emp.pl'). :- consult('subtotal.pl'). :- consult('query.pl'). %Database emp: %emp(Empno, Ename, Job, Mgr, Hiredate, Sal, Comm, Deptno) %dept(Deptno, Dname, Loc) %salgrade(Grade, Losal, Hisal) /* ------------------------------------------------------------------------ */ /* Example -----------------------------------------------------------------*/ /* ------------------------------------------------------------------------ */ /* Find the number of employees who work in Dallas. */ emp_dallas(E) :- emp(E, _, _, _, _, _, _, D), dept(D, _, dallas). nr_emp_dallas(N) :- subtotal(emp_dallas(E), [], [N = count(E)]). /* To run this query, use (in another window, after saving this file): 'pl -s queries_emp.pl' and then (Prolog prompt): make. ?- q(nr_emp_dallas(N)). */ /* ------------------------------------------------------------------------ */ /* Write and test the following queries ----------------------------------- */ /* ------------------------------------------------------------------------ */ %Find average salary of employees who work in Dallas. %For each department (including departments with no employees), find the sum of salaries of employees who work in that department. %Find departments (deptno) with more than 3 employees. %For each department, find the number of analysts who work in that department (the result consists of tuples [D, N]). %Find the job position(s) with the maximal standard deviation of salaries. %Find tuples [Deptno, Job, Sum, Average] which for each [Deptno, Job] state the sum of salaries and average salary of employees who work in department Deptno and do job Job. %Datalog only: For each employee, find the number of subsidiaries (direct and indirect) of that employee. Include employees with no subsidiaries.